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 was one of the most influential figures since Iran's 1979 revolution, criticised for harsh rule but later a key supporter of reformists.
Three days of official mourning began on Monday.
The funeral was expected to see a significant presence of reformists and hardliners, with whom Rafsanjani lost favour in the latter years of his political life.
State television showed a sea of mourners filling the streets around the Tehran University campus, where the funeral prayers were held.
Free bus and metro travel were provided to the venue.
Black banners were raised, and some posters showed the supreme leader and Rafsanjani smiling together. One read, "Goodbye, old combatant".
The former president will be buried next to Iranian revolutionary leader Ayatollah Khomeini.
Rafsanjani was a key supporter of President Hassan Rouhani and had backed Iran's landmark deal with world powers over its nuclear programme.
President 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," Mr Rouhani later said.
Tributes and condolences have come from around the world, though many Iranians have taken to social media critical of Rafsanjani's repression of human rights.
The US State Department, 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.
Rafsanjani's youngest son Yaser, 46, thanked those mourning his father for their "loyalty and kindness".
He told state TV: "I see scenes of affection that I cannot believe. People's prayers for our father console our hearts."
This is the most significant funeral in Iran since the country's revolutionary leader Ayatollah Khomeini was buried in 1989.