DUBAI, Jan 10 (Reuters) - Tens of thousands of Iranians massed in central Tehran on Tuesday for the funeral of former president Akbar Hashemi Rafsanjani in a show of unity to honour the Islamic Republic's polarising pragmatist.
Rafsanjani, who died on Sunday aged 82, will be buried in the mausoleum of Ayatollah Ruhollah Khomeini, who led the country's Islamic revolution in 1979 and founded the country's system of theocratic rule.
Rafsanjani's pragmatic policies of economic liberalisation and better relations with the West attracted fierce supporters and equally fierce critics during his life, but his funeral brought both sides together in a show of solidarity and unity.
Popularly known as a "pillar of the Revolution", he wielded wide influence in core decision-making bodies of Iran.
In a move seen at the time as power-sharing, he played a significant role in 1989 to appoint Ayatollah Ali Khamenei to succeed Khomeini as new supreme leader of Iran.
Rafsanjani was elected as new president a few months later.
However, their friendship gradually turned into rivalry as the pragmatist president sided with reformists who promoted freedoms, while Khamenei followed a conservative interpretation of the core values of the Islamic Republic.
In his condolence message, Khamenei said political differences could never "entirely break up" his nearly 60 years of friendship with Rafsanjani.
Streets were filled overnight with billboards that showed a picture of the two men smiling and chatting as close friends.
"No one would be like Hashemi for me," the billboards quoted Khamenei as saying, using Rafsanjani's first family name. Iranians usually have two family names.
"Ayatollah Hashemi tried all his life to save the Islamic Revolution ... He wanted to preserve the unity of Iran," his son Mohsen was quoted as saying by state news agency IRNA at the funeral.
An eyewitness told Reuters on the phone from Tehran that "some were chanting slogans asking political prisoners to be released, some hardliners were shouting Death to America. But they didn't clash. Everyone were respectful."
Khamenei said the final prayer over Rafsanjani's body in the University of Tehran courtyard where the late president delivered many of his speeches during Friday prayers.
Politicians, military commanders and religious figures from all camps stood behind him.
The president, head of parliament, head of the judiciary and senior Khamenei advisors stood in the first line at the service, while cabinet ministers and the deceased leader's relatives filled the rows behind them.
Rafsanjani's body, sealed in a metal coffin with his white turban on top, was then brought in procession down Revolution Street in central Tehran, where tens of thousands of people came out in cold winter weather to pay tribute.
State television channels broadcast the funeral live from early hours in the morning, highlighting the massive outpouring of public respect for the former president.
Among those attending were Revolutionary Guards Commander Qassem Soleimani, leading Iranian Sunni cleric Molavi Abdolhamid, several grandsons of Khomeini and even some movie stars, showing how Rafsanjani enjoyed respect from opposing figures in Iran.
Mohamad Ali Abtahi, a former vice president and reformist cleric, said on Twitter that "it is difficult to imagine Iran without Hashemi Rafsanjani. He had different opponents in different eras, but they all believed in his greatness and the role he was playing to resolve issues."
Rafsanjani's death ahead of May's presidential election was a blow to moderate president Hassan Rouhani, who allied himself with him to win the 2013 election and went on to resolve Iran's long standoff with the West over its nuclear programme.
Rafsanjani was a member of the Assembly of Experts, the clerical body that selects the supreme leader, Iran's most powerful figure. His absence from that debate, whenever it happens, means the chances of a pragmatist emerging as the next supreme leader are reduced.
Reporting by Bozorgmehr Sharafedin; Editing by Tom Heneghan