Ali Akbar Hashemi-Rafsanjani, who died in Tehran from a heart attack Sunday, was one of the dominant and enduring leaders of the Iranian revolution and the Islamic Republic: a fiery revolutionary, a member of parliament, a shaper of the Islamic Republic’s governing structure, and a moderate president who favored economic reform over religious dictates.

As a young cleric in the 1960s and 1970s, Rafsanjani supported Ayatollah Ruhollah Khomeini, the leader of the revolutionary movement that would ultimately overthrow the shah and establish the Islamic Republic in 1979—activities that got him imprisoned before the shah fell. Following the revolution, he won Khomeini’s confidence, securing a place on the Revolutionary Council, a key policy body and power center. In the revolution’s early years of bitter, often murderous in-fighting between moderates and radicals, both within the clerical community and among the clerics and civilians of the new government, Rafsanjani most often stood on the side of the radicals. He was a founding member of the Islamic Republican Party, Iran’s major clerical political organization after the revolution. He also helped shape the constitution, a document that vested power in the clergy and supreme authority in the person of a clerical supreme leader who, under the constitutional theory of the Islamic Republic, was to serve as a kind of vice-regent to the Prophet Muhammad. He also served as Khomeini’s go-between with Iran’s military forces in the later phases Iran’s eight-year war with Iraq.

But Rafsanjani’s more pragmatic streak began to emerge when he served as speaker of the Majlis, or parliament, for eight years. He sought Khomeini’s help to mediate sharp difference between a parliament committed to radical economic redistribution, and a constitutional watch-dog body, the Guardian Council, that insisted on a conservative interpretation of Islamic law. In the mid-1980s, he was the critical player on the Iranian side in the Iran-Contra affair, when the United States, under President Ronald Reagan, agreed to provide Iran with anti-tank and surface-to-surface missiles in exchange for the release of American hostages held by Iranian surrogates in Lebanon.

During the Iran-Iraq war, some argue that Rafsanjani emerged as a clear voice for peace. After a series of dramatic offensives in 1982, Iranian forces had succeeded in pushing Iraq back across the border. Khomeini’s inner circle debated over whether to continue the war on Iraqi territory in order to take Baghdad and punish the then-leader of Iraq, Saddam Hussein, or to end the war, having resecured Iran’s borders; the former camp won out. That decision proved disastrous: The war dragged on another six years, with terrible human costs. While Rafsanjani’s role in ending the war remains the subject of great debate in Iran to this today, he is believed to have stood with the peace party, and is credited with finally persuading to end the war Khomeini in 1988. Rafsanjani, the pragmatist, realized Iran was exhausted and the war could not be won. On the other hand, there is no indication that he opposed the bloody massacre of thousands of members of left-wing opposition groups already in Iranian prisons near the end of the war.

Rafsanjani also served as head of the Expediency Council, a group that advises the supreme leader on policy, and was a long-term member of the Assembly of Experts, the body that selects the supreme leader. After Khomeini’s death in 1989, Rafsanjani helped engineer the selection of the current supreme leader, Ali Khamenei, as his successor, a choice that Rafsanjani conveniently claimed Khomeini had endorsed on this death bed. Rafsanjani and like-minded members of the inner circle may have thought Khamenei would be pliant; they would soon be disabused of this assumption.

Following Khomeini’s death, Rafsanjani became president in elections in 1989. As president, he tried to ease social controls, open up the economy to the private sector, and improve relations with the outside world, particularly the United States. He also launched a program of reconstruction to deal with the physical damage inflicted by the war with Iraq. Pursuing ties with the United States, he offered a billion-dollar contract to the American oil firm Conoco—a deal that was blocked by President Bill Clinton, for reasons that remain unclear. Rafsanjani’s government also eased social controls: Women were freer to choose their style of Islamic head covering and to wear makeup in public, young men and women could mix more freely in public, and the revolution-era ban on music was eased. Rafsanjani’s minister of culture, Mohammad Khatami, lifted many controls over book publishing, film-making, and theater performances. Rafsanjani, however, displayed little interest in easing controls over the press and political activity.

While Rafsanjani, during his first four years as president, was more influential than Khamenei, that dynamic would eventually reverse. Using the vast authority vested in the supreme leader, his considerable powers of patronage, and careful cultivation of the commanders of the Revolutionary Guards and the heads of the security agencies, Khamenei became the dominant figure in Iran by Rafsanjani’s second term, as hardline policies in foreign and domestic policy alike prevailed.

Towards the end of his presidency, Rafsanjani encouraged a number of the technocrats who had worked with him to form an organization they named the Executives of Construction, to push for policies favoring economic development. The group did well in the parliamentary elections that followed, and in 1997 helped Mohammad Khatami win the presidency. Khatami launched a program of sweeping political and social reforms which, however, were eventually frustrated and reversed by the hardliners.

Rafsanjani also grew wealthy in these years, with his sons translating their father’s prominence and influence to move into a variety of business activities. It was perhaps partly these activities, and Rafsanjani’s caution towards political reforms—versus social and economic reforms, which he embraced—that explains a certain estrangement that developed between Rafsanjani and the Khatami reformers, who wanted sweeping political change. Khatami’s team did not support Rafsanjani’s bid to return to parliament in the 2000 elections. And Rafsanjani, who perhaps hoped to become speaker again but only barely squeaked into the Majlis as a candidate from Tehran, decided not to take up his seat at all.

Iranians liked to refer to Rafsanjani as “the shark,” because of his cleverness, or as the proverbial Iranian cat that despite setbacks always managed to land on its feet. However, in recent years, the power and influence of Iran’s grand man of politics was clearly on the wane. He ran in the 2005 presidential elections, only to be defeated by the populist, Mahmoud Ahmadinejad. Hardliners later accused Rafsanjani of supporting the massive protests that broke out in 2009 when Ahmadinejad was elected to a second term in a contested election. In 2013 he failed in a bid for election as chairman of the Assembly of Experts. He was not able to prevent a son and daughter from serving terms in prison for alleged economic malfeasance and political misbehavior. He was a supporter of the Iran’s nuclear deal with the world powers, a stance which did not sit well with the hardliners.

Rafsanjani’s tentative efforts to integrate Iran into the international community fell short. His death nevertheless not only ends a remarkable political career; it also removes from the scene a politician who in his mature years represented the more pragmatic and moderate tendency in Iran’s deeply divided politics.