The death of Ayatollah Ali Akbar Hashemi Rafsanjani comes at a potentially difficult time for Iran’s relations with the international community, with Donald Trump and his team threatening to tear up the landmark deal over Tehran’s nuclear programme. It also means that the reformist president, Hassan Rouhani, has lost a highly important ally in a crucial stage of his struggle against powerful conservative clerics.

The two issues are not unrelated. Just as the American right, egged on by Israel and Saudi Arabia, has virulently opposed the agreement, so had the hardliners in Iran railed against President Rouhani and his government for what they saw as a surrender of the country’s sovereign rights on defence and security.

Ayatollah Rafsanjani was a towering figure in Iran’s recent history. One of the leaders of the 1979 revolution which overthrew the Shah, he was an aide to Ayatollah Ruhollah Khomeini, effectively the commander-in-chief during the long war with Iraq and then President for eight years.

As one of the small number of journalists allowed into Iran to cover the elections last year, I witnessed how much the ageing Ayatollah had become a source of support for the liberals, and the level of antipathy he attracted among the conservatives in places like Qom, the country’s Shia "Vatican". His opponents had long turned against him for his calls for greater civil rights, trying to find an accommodation with the West and, not least, for his backing the nuclear agreement.

Donald Trump promised on the campaign trail to pull the US out of the nuclear deal once he was in power. He told an Israeli lobbying group that “it was the worst deal ever negotiated” and that it was his “number one priority to dismantle it”. The agreement has been denounced by Lieutenant General Michael Flynn, who will be the President-Elect’s National Security Advisor and Mike Pompeo, who is taking over as director of the CIA, tweeted that he looks forward to “rolling back this disastrous deal”. The Trump administration is being encouraged to take a hard line by Israel, which continues to see Iran as "an existential threat", and Saudi Arabia, the leader of the Sunni Gulf States, locked in a sectarian confrontation with Shia Iran.

The President-elect has received a series of appeals, ranging from prominent Iranian-Americans including those who are opposed to the Tehran government, and 37 senior scientists, including Nobel laureates, not to scrap the agreement. General James Mattis, the new Defence Secretary, and Senator Bob Corker, chair of the US Senate Foreign Relations Committee, have also cautioned against hasty action.

But the unpredictability over what Mr Trump may actually do continues. Even if there is no immediate action over the nuclear deal, he has talked repeatedly of imposing new sanctions on Iran over its missile programme and support for groups like Hezbollah abroad.

The hardliners in Iran are taking advantage of this uncertainty. They have launched another campaign against the nuclear agreement claiming that President Rouhani was “tricked” into the deal by “treacherous America”. Javad Karimi Ghoddousi, a member of the National Security and Foreign Policy Committee of the Iranian parliament, recently circulated notes of alleged conversations between foreign minister Mohammad Zarif, one of the architects of the agreement, and his aides, in which he supposedly admits that he was “naïve” to trust US Secretary of State John Kerry.

But even if the notes are forged, the suspicion they have generated in a febrile climate – that fresh American sanctions after Mr Trump moves into the White House – may result in Mr Rouhani losing in election due in a few months’ time, according to Dr Farhad Rezaei, a writer on Tehran’s foreign policy and nuclear programme.