
Khamenei and several members of his family were killed in an Israeli strike on his residence in Tehran on 28 February, the first day of Iran's war with the US and Israel.
He was succeeded as supreme leader by his son Mojtaba, who has not been seen in public since he was reportedly seriously wounded in the same attack.
The 56-year-old did not participate in the funeral ceremonies in Tehran and Qom, and there has been no indication that he will attend the burial.
On Thursday morning, a plane carrying the coffins of Ali Khamenei and four other members of his family landed in Mashhad after flying from Iraq, where huge crowds took part in processions to two Shia shrines in the cities of Najaf and Karbala.
Later, Iranian TV footage showed thousands of mourners dressed in black walking along a main boulevard in central Mashhad. Many were waving Iranian flags and red banners symbolising vengeance.
Some people were also holding photos of the late supreme leader and placards calling for the death of US President Donald Trump, who, along with Israeli Prime Minister Benjamin Netanyahu, ordered the joint attack on Iran four months ago that triggered the war.
Hanging above the boulevard were banners with official slogans including "We must rise".
Khamenei will be buried in a tomb at the shrine of Imam Reza, the eighth Shia imam and the only one believed to have been buried in Iran.
The mausoleum, which dates to the 9th Century and has a towering golden dome and minarets, is visited by millions of pilgrims each year.
Khamenei was born in Mashhad, Iran's second-largest city located in the northeast of the country, and studied at seminaries in the city before moving to Qom, the centre of Iran's Shia clerical establishment.
He was appointed supreme leader in 1989 after the death of the Islamic Republic's founding father, Ayatollah Ruhollah Khomeini.
During his 37 years in power, he maintained a firm grip on Iran's politics and its armed forces, and suppressed domestic challenges, sometimes violently. He also took consistently hard-line stances on external matters, including Iran's confrontation with the US and Israel.
Iran's leadership wanted the choreographed funeral ceremonies for Khamenei to project unity and strength after a war, during which thousands of people have been killed, and the mass protests in January, when a crackdown by security forces left thousands more people dead.
The public mourning has, however, been marred by the renewed hostilities with the US.
Trump warned that US attacks could get "much worse" after a second night of strikes on Thursday, which the US military said were intended to degrade Iran's ability to target commercial shipping in the Strait of Hormuz.
The Revolutionary Guards said Iranian forces had attacked US military facilities and infrastructure in Kuwait, Bahrain and Qatar in response.
Three weeks ago, the US and Iran signed a memorandum of understanding (MoU) that called for an end to hostilities on all fronts and the reopening of the Strait of Hormuz. It also gave them two months to reach a final deal that covers Iran's nuclear programme, US sanctions and a permanent truce.
Last week, mediator Qatar said Iranian and US negotiators made progress at indirect talks in Doha following a four-day exchange of strikes, and that their next meeting would take place after the conclusion of the ceremonies for Khamenei.
But on Wednesday, Trump told reporters that he believed that the MoU was now "over".
