Iran has already contributed to progress in Iraq by agreeing to the removal of Nouri al-Maliki, the divisive Shiite partisan who was prime minister. Iran now must support an inclusive Iraqi regime that gives full rights and opportunities to the Sunnis within Iraq, with a U.S.-supported and reinforced Iraqi military, to keep the ISIL threat from moving directly to Iran’s borders.

At the same time, however, Iran has been vigorously supporting Bashar al-Assad’s regime in Syria against both moderate and extremist rebels. That places Iran squarely in opposition to President Obama’s plan to build up a moderate rebel force capable of taking on both ISIL and the Assad regime forces and winning.

This creates a delicate diplomatic dilemma, but also a great opportunity. If Iran can be persuaded to adopt a similar role in Syria to the role it is already accepting in Iraq—assent to an inclusive, majority-led but minority-respecting regime, with the United States playing an active role in supporting the military forces of the government—and therefore to withdraw its active support of Assad, Iran can align itself with the broader Sunni coalition that President Obama is seeking to back a political solution in Syria.

Creating such an alignment will be incredibly difficult, but it could bring huge benefits to the entire Middle East. Beyond the immediate crisis of ISIL in Syria and Iraq, co-operation between the United States and Iran, and between Iran and Sunni states in the region, in supporting inclusive states in both Syria and Iraq could help to reduce the Sunni-Shia rifts that have kept the region in turmoil. The civil wars in Iraq and Syria as well as in Yemen and unrest in Bahrain and Saudi Arabia are all fueled by the “all or nothing” approach to Islam of Sunni and Shia groups in their countries, much like the Protestant vs. Catholic struggles that fueled the Thirty Years War in 17th-century Europe.

This deep sectarian divide is a major factor driving the region’s bloody chaos. A regional diplomatic effort to help overcome Sunni-Shia divisions and gain Iran’s support for key measures to defeat ISIL is thus a crucial part of any winning strategy. Key intermediaries, such as the new prime minister of Turkey (and former foreign minister) Ahmet Davutoğlu, and the new prime minister of Iraq, Haidar al-Abadi, might be the best persons to lead this diplomatic effort, and should be encouraged to talk to Iran.

Until the leaders of the major Middle Eastern countries resolve to accept people of all faiths, including all Muslims, Christians and others as full citizens, it will be impossible to have security and stability in the region once the revolutionary genie, seeking ideological purity, has been let out of the bottle.

It also means that the leaders of the Arab countries as well as Iran will need to give open support for a moderate Syrian regime that excludes Assad and all those in his regime responsible for atrocities against the Syrian people. That can be a government led by defectors and mid-level professionals in the current Syrian administration, or one created by the opposition in exile and in rebellion. Either way it will have to be inclusive and receive international support in providing security and recovery for the masses of ordinary Syrians who have suffered from Assad’s war against his people.

As long as Assad is in power in Syria, however, ISIL will have an ideal recruiting environment to draw ever more fighters and supporters to its cause. Assad’s departure is thus not a later phase that can be dealt with after a military campaign; it is an essential part of the strategy to make any military campaign effective. And Iran’s cooperation is essential for forcing Assad to relinquish power. Integrating Iran into any strategic plan will be challenging, but success is impossible without it.

Many—including Israeli Prime Minister Benjamin Netanyahu—would say a focus on Iran’s nuclear program remains more important. But that issue cannot be separated from the ISIL threat and the U.S. strategy to deal with it. Iran’s pursuit of nuclear capabilities is motivated by Iran’s desire for respect and security. If Iran finds itself supporting the Assad regime in Syria while American-supported forces are aiming to overthrow it; and if Iran finds itself left out of a broad regional U.S.-backed Sunni coalition seeking to direct politics in the region, then Iran is likely to become more hostile, and feel an even greater need to develop its nuclear capability.

Indeed, in response to Secretary of State John Kerry’s open reluctance to include Iran in the coalition against ISIL, Iranian officials have already questioned the sincerity of America’s opposition to the militant group. Iranian officials have characterized the anti-ISIL coaltion as  “suspicious” and openly attacked U.S. plans to conduct air strikes and support rebels in Syria. But if, in contrast, Iran finds itself in alignment with the actions of the United States and of Sunni countries in the region, and feels that it has played a significant role in the development of stable and friendly Syrian and Iraqi regimes, it is more likely to accept limits on its nuclear capabilities as the reduction of Sunni-Shia conflicts improves its own security.

Nobody should underestimate the challenge of defeating ISIL. But the prospect of this crisis leading to an alignment of U.S., Sunni and Iranian interests holds out the prospect of finally creating lasting stability in the Middle East. The end of the Thirty Years War produced almost five decades of subsequent peace in Europe; the end of the Napoleonic wars similarly produced peace among Britain, France and Germany for almost 60 years. If the revolutionary threat from ISIL leads to an unlikely coalition embracing NATO, Sunni regimes and Iran to defeat that threat, we may hope that, however long it takes to achieve, the result will also be a peace that lasts.

It’s a once-in-a-generation opportunity. Does Obama have the courage to seize it?

The opinions expressed here are solely those of the author.

The original article was published by Politico Magazine.