Hundreds of thousands of mourners led by Iran's supreme leader have gathered at Tehran University for the funeral of former president Akbar Hashemi Rafsanjani.

State television showed people pouring on to the streets around the campus where Ayatollah Ali Khamenei led the ceremony for Rafsanjani on Tuesday.

Khamenei stood next to President Hassan Rouhani and Parliament Speaker Ali Larijani as they prayed in front of Rafsanjani's closed casket.

A huge crowd line Tehran streets to say farewell to Hashemi, a politician with a complicated record who regained popularity in recent years. pic.twitter.com/joWMIrElg9 — Sadegh Ghorbani (@GhorbaniSadegh) January 10, 2017

Images posted on social media also showed Quds Force commander Qassem Soleimani attending the funeral procession.

However, there have been reports that reformist leader and former president Mohammad Khatami was banned from attending Tuesday's event.

Rafsanjani, who died of a heart attack on Sunday at the age of 82, will be buried inside the crypt of Ruhollah Khomeini, the leader of Iran's 1979 Islamic revolution, according to Al Jazeera's Dorsa Jabari, who is reporting from the Iranian capital.

"It's a very sombre occasion in the Islamic Republic," Jabari said. "This was something very unexpected. Many ordinary people, who weren't necessarily even fans of Rafsanjani, or his family, expressed their views that they were just shocked and extremely saddened by the loss."

Khomeini's mausoleum is in south Tehran near the capital's largest airport.

Leaders of all of Iran's competing political factions also attended the funeral.

Black banners were raised in Tehran and some posters showed the supreme leader and Rafsanjani together smiling. Another poster said "Goodbye, old combatant".

Authorities have declared Tuesday a public holiday so Iranians can commemorate Rafsanjani.

Free bus or metro travel was provided to the funeral venue.

acrdng "#Iran" State npaper,≈4.5M participated in #hashemirafsanjani's funeral-Hashemi:conservative in90s but face of moderates aftr 2005 pic.twitter.com/VAhkHH9R3K — ERSHAD ALIJANI (@ErshadAlijani) January 10, 2017

#همه_آمدیم بخشی از شعارهای مردم (۲): «یاحسین، میرحسین» و «عزا عزاست امروز، روز عزاست امروز، امام جمعه‌ی ما، پیش خداست امروز» @Vahid pic.twitter.com/OeeTmsXwrM — M Jalaeipour (@MJalaeipour) January 10, 2017

Since Rafsanjani's death, messages of condolence have poured in from home and abroad.

Even the White House sent a message, unprecedented since the 1979 revolution that led to the cutting of ties between Tehran and Washington.

Rafsanjani, a close aide to both Khomeini and Khamenei, served as president from 1989 to 1997.

He was also a major supporter of Rouhani and served as a go-between for reformers seeking outreach to the world and hard-liners.