Hashemi Rafsanjani, the President of Iran from 1989 to 1997 and still an influential and controversial figure in Iranian politics, died on Sunday following a heart attack.

Rafsanjani, 83, suffered the attack about 6 p.m. and passed away about 7:30 p.m. (1600 GMT) at Shohada Tajrish Hospital in northern Tehran. President Hassan Rouhani was present.

The former President’s body has been taken to the Jamaran district, near the home of the late Ayatollah Khomeini.

Although embattled within the regime since the 2009 mass protests over the disputed Presidential election, Rafsanjani still held the chair of the Expediency Council and was regarded as Rouhani’s mentor.

See Iran Analysis: Tehran Prepares for Politics Without Rafsanjani

Despite his tension with the former President — to the point of limiting his power, putting pressure on his family, and blocking Rafsanjani’s run for the Presidency in 2013 — the Supreme Leader issued an effusive message of condolence:

The loss of a comrade, a companion with whom one has cooperated and felt close to for a full 59 years, is difficult and overwhelming….

His unique intelligence and friendliness throughout the years turned him into a reliable source of trust for all those who worked with him, particularly me.

At times, a difference of opinions and varying jurisprudences, during this long companionship, never managed to cut the ties of friendship between us….The evil set forth by those who breathed temptation into the minds of people, who were trying hard over the last few years to exploit these theoretical differences, could not lead to any flaws in the deep, personal love he felt for this humble person….

I ask God for compassion, mercy and forgiveness towards him, from the depths of my heart, and I condole with his respected wife, children, brothers and other survivors.

Maneuvers Within Regime

Rafsanjani was a member of the inner circle of the founder of the Islamic Republic, Ayatollah Ruhollah Khomeini. He quickly became Speaker of Parliament after the 1979 Islamic Revolution. As head of the Assembly of Experts, the body which chooses the Supreme Leader, he was instrumental in the selection of Ayatollah Khamenei after Khomeini’s death in 1989.

Rafsanjani became President a few months later. He pursued the reconstruction of Iran after the damaging 1980-1988 war with Iran, encourging privatization while seeking links with Central Asia and Arab states, including reconciliation with Saudi Arabia. Success was limited, however, and the reformist Mohammad Khatami won the Presidency in 1997.

He remained prominent in Iranian politics and ran for President in 2005. However, plagued by allegations of corruption around his personal wealth, he lost to Mahmoud Ahmadinejad and settled for a return as head of the Assembly of Experts in 2007.

From Leadership to Challenge

In July 2009, weeks after the mass protests over the disputed re-election of Ahmadinejad, Rafsanjani used his sermon as Tehran Friday Prayer leader to call for acceptance of the demonstrations.

He immediately fell out of favor with key figures in the regime, including the Supreme Leader. The Friday Prayer was his last, and he lost the chair of the Assembly of Experts in 2011, although he remained as head of the Expediency Council.

The regime also maintained pressure on Rafsanjani through the arrests of two of his children. His son Mehdi Hashemi was accused of election manipulation and fraud after the 2009 Ahmadinejad “victory” and was finally arrested in September 2012. His daughter Faezeh Hashemi was imprisoned for six months in 2012 for her activism.

However, turmoil over Ahmadinejad’s final years in office gave Rafsanjani another opening. With support appearing to build behind him, he announced his candidacy for the Presidency in 2013. He was banned by the Guardian Council, but the Council’s “consolation” of allowing Hassan Rouhani to run turned into a surprise victory for the current President and an opening for a centrist bloc in which Rafsanjani was influential.

The former President continued to spur controversy. He incurred the wrath of hardliners and Khamenei’s office with his suggestion that the Supreme Leader, upon his death, be replaced by a five-cleric council with a limited term. His renewed promotion of reconciliation with Saudi Arabia was undermined by the breaking of relations between Riyadh and Tehran in January 2016.