It is over three decades since Iranian students stormed the US embassy in Tehran crying, “Death to America!” The embassy complex still stands, but it now serves as a training complex for the Revolutionary Guard. Next to memorials to Ayatollah Khomeini and the “martyrs of the revolution” is the “Den of Spies” museum. One highlight on display there is the “glassy room” – a room US diplomats would go to for top-secret conversations. It is a suspended box made of Plexiglas, with transparent walls, floors and ceiling that make it impossible to conceal bugs. The hope of the great powers is that the historic deal struck with Iran on 13 July will make the country’s nuclear programme as transparent and as contained as this.

If the agreement is ratified by the US Congress – given Republican hostility, this cannot be taken for granted – it will, it is hoped, stop Iran from covertly developing nuclear weapons and avert a bombing raid by Washington or Tel Aviv. However, even if the deal is passed, there will be little hope for peace in a region that is already in flames: witness Libya, Syria and Yemen. How will a nuclear deal affect this instability?

The nightmare scenario is one of “Tehran unbound”: a situation where all constraints are lifted and an emboldened Supreme Leader and the Revolutionary Guard are allowed to wreak havoc in the region with impunity. The question is whether the EU and the US – which have successfully negotiated the deal that lifts sanctions on Iran but places strict limits on its nuclear programme – can influence Iran’s regional policies more effectively with engagement than they have done with containment. Or could Iran eventually even play a constructive role in the region?

It is an open question. Visitors to Tehran are always struck by the dizzying complexity of Iranian politics and society. The paradox of 1979’s religious revolution is that it has given birth to the most secular society in the region. More than 70 per cent of Iranians were not even born when the revolution took place, and they are self-consciously more pragmatic, moderate and open to the west than any of their peers in the Middle East. But in terms of its role within the region, Iran is one of the leaders of a violent sectarian conflict; and its leaders are enjoying the new space that has been accorded to them by the toppling of Saddam, the Taliban, and by western mistakes in the region.

George W Bush’s war on terror set off a chain of events that is now putting irresistible pressure on the states created after the First World War. Borders that the US has guaranteed in the post-colonial era are now dissolving and new units – such as Kurdistan and Islamic State – are emerging from the ruins. If you want to find out about the decline of US power in the Middle East, go to Tehran. Few chant “Death to America” these days, and when such chants are heard they come across as more of a nostalgic echo than a rallying cry for Iran’s future.

When I talked to Iranian policymakers last year, they told me US hegemony in the Middle East and global affairs is giving way to a multipolar order. The Great Satan for them is no longer the United States – it is Saudi Arabia. Iranians complain about the Saudis drilling more to reduce oil prices and weaken Tehran; they are concerned about the enhanced military co-operation between members of the Gulf Co-operation Council, oriented against Iran; and about Saudi Arabia challenging them in Afghanistan, Iraq, Lebanon and Syria.

In Riyadh I find an exact mirror image of those suspicions. Saudis are obsessed with Iranian activism in Bahrain, Iraq, Lebanon, Syria and Yemen. The geopolitical tussle between these two nations is emblematic of a new Middle East where emancipated local powers are battling it out. Order is no longer defined and defended by Washington. Instead, the US is seen as a resource that Tehran and Riyadh can manipulate in their struggle against one another.

So, what role can the US and EU hope to play in this new Middle East? For the US, the challenge of getting the deal through Congress will demand that Obama go to great lengths to reassure Riyadh and Tel Aviv it is not abandoning them in its links to Tehran or its pivot to Asia. It can continue to co-ordinate its strikes against Isis with Tehran but will be wary about being seen to be getting too cosy with Ayatollah Khamenei.

But Europe, for which the stakes are even higher than for the US, is less constrained in its ability to reach out to different players. As Ellie Geranmayeh argues in an interesting policy paper, Engaging With Iran: a European Agenda, there is a unique chance to construct a regional strategy on the foundations of the Iran nuclear deal.

The EU high representative Federica Mogherini has an opportunity to build on the nuclear talks by quickly opening an EU embassy in Tehran and exploring how economic links could lead to a bilateral détente. More importantly, she should explore whether the “E3+1” grouping – of France, Germany, the UK and the EU – could be reconfigured from having a nuclear focus to one pushing for regional peace. The agenda should be to try, over time, to find ways of reducing tensions between Iran and Saudi Arabia. This could involve confidence-building on Yemen, co-ordination of the anti-Isis campaign in Iraq and Syria, and discussing other thorny issues such as Hezbollah’s role, or even relations with Israel.

There are limits to what can be achieved in the short term. Both Tehran and Riyadh are enjoying their moment in the sun and for both sides the rewards outweigh the risks. However, the successful conclusion of the Iranian nuclear deal showed the power of strategic patience. The challenge now will be to show the same level of diplomatic creativity in a quest for peace. For Europe and the US – as well as for the regional powers locked in a conflict that neither side can win – the hope must be to contain the conflict before the whole region gets sucked into a Thirty Years War.

Mark Leonard is the co-founder and director of the European Council on Foreign Relations