Former Iranian president Akbar Hashemi Rafsanjani died on Sunday aged 82 after suffering a heart attack, according to state media.

Rafsanjani was a key figure in the foundation of the Islamic republic in 1979, and served as president from 1989 to 1997.

He was taken to the Shohada hospital, in northern Tehran,  earlier on Sunday with heart problems, the ISNA and Fars news agencies reported.

"Akbar Hashemi Rafsanjani was transferred to hospital after a heart attack," said Reza Soleimani, a speaker of the Expediency Council, Iran's main political arbitration body which Rafsanjani chaired.

"Despite the efforts of the doctors he died," he said, quoted by state broadcaster IRIB.

READ MORE: Dear Iran

Al Jazeera's Dorsa Jabbari, reporting from Tehran, said Rafsanjani's death was  described as a "huge loss" by Iranian officials.

"His death couldn't come at a worse time for the country because there are disputes between the current government and the judiciary and Rafsanjani was seen as a mediator," she said. 

"He would advise on how to deal with such situations in the country. With the news of his death many people are in absolute shock."

Following the announcement of Rafsanjani's death, a crowd gathered outside the hospital in Tehran's Tajrish neighbourhood where the former president had been taken.

'Difficult and overwhelming'

Rafsanjani was born on August 25, 1934, in the village of Nough, in southern Iran, into a wealthy family.

He studied theology in the holy city of Qom before entering politics in 1963 after the shah's police arrested the founder of the Islamic republic, Ayatollah Ruhollah Khomeini.

A confidant of Khomeini, Rafsanjani was the speaker of parliament for two consecutive terms until Khomeini's death in 1989.

Ayatollah Ali Khamenei, Iran's supreme leader,  paid tribute to Rafsanjani as a "companion of struggle" despite differences between them.

"The loss of my companion of struggle, whose cooperation with me dated back 59 years, is difficult and overwhelming," Khamenei said in a statement quoted by the state broadcaster's website.

"The different opinions and interpretations at time in this long period could never entirely break up the friendship" between us, he added.

READ MORE: Iran 37 years later - Any hope for reforms?

Rafsanjani was an influential figure in Iran, and headed the Expediency Council, a body which is intended to resolve disputes between the parliament and the Guardian Council.

He was also a member of the Assembly of Experts, the clerical body that selects the supreme leader, Iran's most powerful figure.

Rafsanjani has been described as "a pillar of the Islamic revolution".

His pragmatic policies, economic liberalisation, better relations with the West and empowering Iran's elected bodies, appealed to many Iranians but was despised by hardliners.

His death is a big blow to moderates and reformists, depriving them of their most influential supporter in the Islamic establishment.

He is survived by his wife and five children.

Source: Al Jazeera and news agencies