Hundreds of thousands of Iranians have turned out in the capital, Tehran, for the funeral of former President Akbar Hashemi Rafsanjani.
Supreme Leader Ayatollah Ali Khamenei led the prayers at the ceremony.
Rafsanjani, president from 1989 to 1997, died of a heart attack on Sunday at the age of 82.
He had been one of the most influential figures since the 1979 revolution, criticised for his harsh rule but later becoming a key supporter of reformists.
In a statement issued on Sunday, the supreme leader lamented the death of a "comrade and ally" with whom he had been friends for almost 60 years.
But he also alluded to their rivalry in recent years, acknowledging "differences in views and interpretations of Islamic law in various points of this long time".
Tuesday's funeral prayers were attended by senior political, military and religious figures from both the reformist and hardline camps, including President Hassan Rouhani and Revolutionary Guards commander Qassem Soleimani.
Many joined Ayatollah Khamenei in kneeling before Rafsanjani's metal coffin, on which his white cleric's turban was placed, and touching it.
State television showed a sea of mourners in the streets around the Tehran University campus, where the prayers were held.
Black banners were raised, and some posters showed the supreme leader and Rafsanjani smiling together. One read: "Goodbye, old combatant."
Some mourners chanted the name of Rafsanjani's successor as president, Mohammed Khatami, prompting state television to turn up the background music on its live broadcast.
Iranian media are banned from mentioning Mr Khatami's name or publishing photographs of him, as hardliners in the judiciary attempt to limit the influence of the prominent reformist who led the country from 1997 to 2005.
Mr Khatami appeared to have been prevented from attending Tuesday's funeral.
Goodbye to a major figure, by Lyse Doucet, BBC Chief International Correspondent
This is the most significant funeral in Iran since the country's revolutionary leader Ayatollah Khomeini was buried in 1989.
Akbar Hashemi Rafsanjani was one of the last major figures of the 1979 revolution.
In its early years, he was known for his harsh rule. But over the decades, the wily politician who held almost every major position in government became known for his pragmatic approach to Iran's theocracy.
He pushed for a greater rapprochement with the West and more social and economic freedoms.
His credentials gave him the courage and the clout to speak out. The reformists he backed, including the current President Hassan Rouhani, have now lost a key ally in their incessant struggle for power against the hardliners.
Both he and Rafsanjani supported Mr Rouhani in the 2013 presidential election and backed Iran's landmark deal with world powers over its controversial nuclear programme.
Mr Rouhani was reportedly at Rafsanjani's hospital bedside in Tehran on Sunday where doctors had fought to save him.
"Islam lost a valuable treasure, Iran an outstanding general, the Islamic revolution a courageous flag-bearer and the Islamic system a rare sage," the president said.
Tributes and condolences have come from around the world, though many Iranians abroad have taken to social media to criticise the suppression of dissent and human rights under Rafsanjani.
Rafsanjani was also accused by Argentine prosecutors of complicity in the 1994 bombing of a Jewish community centre in Buenos Aires that killed 85 people.
And a German court concluded that in 1992 - during Rafsanjani's presidency - Iran's political leadership had ordered the killing of four exiled Iranian Kurdish dissidents in Berlin.
Rafsanjani was also the assumed head a family business empire that has a near monopoly on the lucrative trade in pistachio nuts, owns Iran's second biggest airline and controls the country's largest private university. In 2003, his fortune was estimated by Forbes magazine at more than $1bn.
The US, a bitter foe of Iran during Rafsanjani's tenure, described the ex-president as a "prominent figure" in Iranian history, saying it sent its condolences to his family.