In Iran a few weeks ago I travelled with my 11-year-old son from Tehran to the ancient fire temple at Takht-e Soleymān, not far from the Iraqi border. At no time during our journey – part of which was made in a clean, comfortable, Chinese-made train – did we feel anything but safe. Our only exposure to violence was in the provincial town of Zanjan, famous for its knife production, where a salesman dry-shaved his own forearm in demonstration of his wares.

No one in their right mind would undertake a comparable journey nowadays inside the borders of any of Iran’s war-torn neighbours: Iraq, Afghanistan, or, a bit further afield, Syria. Iran is the exception along the Middle East’s strategic, resource-rich central belt, a functioning nation state where the central authorities enjoy a monopoly of force, the infrastructure works and the people are overwhelmingly literate and unarmed. Perhaps most significant of all, as capo di tutti capi of the Shia world – wielding clout over its co-religionists in Iraq and Lebanon as well as propping up Bashar al-Assad with military assistance and subsidised oil – Iran could have a vital role in restoring stability throughout Mesopotamia and the Levant.

I say “could” because there is no guarantee that the Iranians will be invited to assume the role that common sense assigns them. It’s one of the perversities of modern politics that the west does not have a decent working relationship with the most important country in the Middle East.

Negotiations to that end have been going on for the past year between Iran and the so-called P5+1 (the five permanent members of the United Nations security council plus Germany), and last week at the UN general assembly David Cameron met the Iranian president, Hassan Rouhani – the first such meeting since the 1979 revolution.

Improved atmospherics, however, cannot hide the fact that the only substantive achievements of the diplomatic process so far – a freeze on key parts of Iran’s nuclear development in exchange for a freeze on further sanctions – are reversible.

And now is crunch time; for 24 November, the final day of negotiations, is just eight weeks away, and big differences remain over the scope of the uranium enrichment programme that Iran will be allowed to retain. At the same time the incomplete alliance that the US has built against the militants of Islamic State (Isis) – including Sunni monarchies such as Saudi Arabia, which have a history of fanning Shia-phobia (and anti-infidel hatred more generally), while keeping Iran at arm’s length – illustrates once again the illogic of the western approach.

It was almost impossible to argue in favour of a detente with Iran during the dreadful government of Mahmoud Ahmadinejad, who presided over a galloping nuclear programme and an ailing economy even as he advocated Israel’s elimination. But in August 2013 he was replaced by Rouhani, a partly British-educated cleric whose election message of balance in all things chimed with reformist voters as well as the conservative supreme leader, Ayatollah Ali Khamenei.

The new president has since scored notable successes – while keeping Khamenei on side, despite the latter’s scepticism over nuclear talks. Rouhani has used the momentum generated by the interim deal – in addition to the modest sanctions relief that accompanied it – to cut inflation from 45% to 20% and stabilise the rial currency after it lost more than 80% of its value.

Human rights in Iran remain wretched – as exemplified by the continued incarceration of Ghoncheh Ghavami, a British-Iranian woman who was arrested this summer after trying to enter an all-male sports arena, and is now charged with “propagandising against the regime”. But abuses of this kind are not Rouhani’s doing (he does not control the conservative judiciary), and many Iranians agree that, for the moment, the president’s priorities should be economic and diplomatic.

With his moderation, his promotion of technocrats over ideologues – the Iranian cabinet boasts more US-educated PhDs than the American one, foreign visitors have been heard to joke – and his apparent imperviousness to conservative darts, Rouhani has the look of a survivor. He might well achieve his aim of turning Iran into a more open society and unleashing its economic potential – think of Turkey in the early 2000s, only with an abundance of oil and gas. An Iran that was integrating would conform more often to international norms, and would eagerly supply natural gas to Europe as the Russian flow dwindles.

Whatever happens, Syria is an apple of discord, but there is the shared imperative of combating Isis – whose primary foe is not the west but the Shias, whom it derides indiscriminately as “Safavids”, after the 16th-century dynasty that turned Iran into a Shia state. Against the many hundreds of Shias who have been butchered by Isis, the number of westerners who have lost their lives at its hands is tiny.

So it was disconcerting to hear Israel’s President Binyamin Netanyahu, in his speech to the UN this week, dismiss Rouhani’s earlier denunciation of Isis terrorism as “crocodile tears”. Netanyahu also warned against his “manipulative charm offensive”, designed to “remove the obstacles to Iran’s path to the bomb”. This caricature may have some basis in Netanyahu’s fear that a rehabilitated Islamic Republic could dislodge Israel from western affections – a process already well advanced by the widespread killing of Palestinian civilians during the recent violence in Gaza.

The US and its allies have not enjoyed much recent success in influencing internal Iranian politics, but they should be aware that Rouhani’s continued political prosperity, and that of the more hopeful Iran he represents, is dependent in large measure on success in the current negotiations.

If they succeed and sanctions begin to be lifted, the country could advance rapidly as oil sales rebound to 2.2m barrels a day (up from 1.3m), and the country gains access to an estimated $100bn in frozen assets abroad.

Failure could bring an equally quick unravelling, however, with the US Congress imposing new sanctions after November’s midterm elections, and an inevitable Iranian response. Amid renewed uncertainty the economy would again dive, discrediting Rouhani and all he stands for. And that would be a disaster – for Iran, for the region, and ultimately for the west.

Whatever the ingenious face-saving formulas proposed by the policy wonks over the next few weeks, it is the political will of Barack Obama on the one hand, and Khamenei and Rouhani on the other, that will decide the fate of the negotiations. Only in circumstances of the direst national peril would Iran make the suicidal lunge for a bomb, and it is up to both sides to ensure that such a peril never arises.

A deal that offers Iran a nuclear power industry not exceeding its needs and ambitions, and the rest of the world reassurance through intrusive inspections, would do more than bring Iran in from the cold. It would inaugurate a new relationship between the Islamic Republic and the west that could keep together a region that is, in every other particular, coming apart.