President Donald Trump has threatened to impose sanctions on Iraq and demand billions of dollars in compensation if it expels American troops, in retaliation for a US strike in Baghdad that killed one of Iran’s top generals.

The comments, which only ratcheted up soaring tensions in the region, came as Iran’s Supreme Leader Ayatollah Ali Khamenei led emotional funeral prayers in Tehran over the remains of General Qassem Soleimani, the slain head of the Quds Force, the foreign military arm of Iran’s elite Revolutionary Guards.

Iranian state TV claimed millions had poured onto the streets of the Iranian capital to bid farewell to the feared commander who was killed in a US drone strike Baghdad airport on Friday.

The scale of the crowds shown appeared to be the biggest since the 1989 funeral of the founder of the Islamic Republic, Ayatollah Ruhollah Khomeini, who led the 1979 revolution that set Iran on its political collision cause with Washington.

Mr Trump, who has twice threatened to target Iranian cultural sites despite the action being a possible war crime, also lashed out at Iraq.

Baghdad’s leadership denounced the targeted killing of Soleimani in its territory as a gross violation of its sovereignty. On Sunday the Iraqi parliament passed a resolution telling the government to end the presence of foreign troops in Iraq and ensure they not use its land, air, and waters for any reason.

US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Show all 35 1 /35 US airstrike kills Iran's Qassem Soleimani: Fallout in pictures US airstrike kills Iran's Qassem Soleimani: Fallout in pictures This photo released by the Iraqi Prime Minister Press Office shows a burning vehicle at the Baghdad International Airport following an airstrike in Baghdad, Iraq, early Friday 3 January AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures The wreckage of the car in which general Soleimani was travelling when a targeted US airstrike struck outside Baghdad International Airport on 3 January Ahmad Al Mukhtar via Reuters US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Demonstrators burn the US and British flags during a protest in Tehran after general Soleimani was killed in a targeted airstrike by American forces Reuters US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A burning vehicle at the Baghdad International Airport following an airstrike. The Pentagon said Thursday that the US military has killed general Qassem Soleimani, the head of Iran's elite Quds Force, at the direction of Donald Trump AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Protesters burn Israeli and US flags as thousands of Iranians take to the streets to mourn the death of general Soleimani at the hands of America EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Supporters of Donald Trump pray at an 'Evangelicals for Trump' campaign event held on the day following the killing of general Soleimani. At the event, the president praised the "flawless strike that eliminated the terrorist ringleader" AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A huge procession of mourners gather in Baghdad for the funeral of general Soleimani on 4 January AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Thousands of Iranians take to the streets to mourn the death of Soleimani during an anti-US demonstration to condemn the killing of Soleimani, after Friday prayers in Tehran, Iran EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iraqis perform a mourning prayer for slain major general Qasem Soleimani of the Iranian Revolutionary Guards at the Great Mosque of Kufa AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A billboard reading 'Death to America and Israel', installed by Iran-backed shiite armed groups at a street in Jadriyah district in Baghdad, Iraq EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A handout picture provided by the office of Iran's supreme leader Ayatollah Ali Khamenei shows him visiting the family of Soleiman KHAMENEI.IR/AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Thousands of Iranians take to the streets in Tehran EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Pakistani Shiite Muslims burn a mock of a US flag as they hold pictures of General Qasem Soleimani during a protest against the USA, outside the US Consulate in Lahore, Pakistan EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iran's Ambassador to Lebanon Mohammed Jalal Feiruznia, looks to a portrait of Soleimani, as he receives condolences at the Iranian embassy, in Beirut, Lebanon AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures People make their way on the street while a screen on the wall of a cinema shows a portrait Soleimani in Tehran AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Aziz Asmar, one of two Syrian painters who completed a mural following the killing of Iranian Revolutionary Guards commander Qasem Soleimani poses next to his creation in the rebel-held Syrian town of Dana in the northwestern province of Idlib AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A demonstration in Tehran AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures An anti-US demonstration to condemn the killing of Soleimani, after Friday prayers in Tehran EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Mujtaba al-Husseini, the representative of Iran's supreme leader Ayatollah Ali Khamenei, delivers a speech in the holy shrine city of Najaf AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Pakistani Shiite Muslims burn a mock of a US and Israeli flags as they hold pictures of General Qasem Soleimani during a protest against the USA, outside the US Consulate in Lahore, Pakistan EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Protesters demonstrate in Tehran AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Pakistani Shi'ite Muslims hold pictures of General Qasem Soleimani during a protest against the USA, in Peshawar, Pakistan EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Protesters, holding a photograph of the leader of the People's Mujahedin of Iran Massoud Rajavi, outside Downing Street in London PA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Protesters burn a US flag in Tehran AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A Syrian man offers sweets to children to mark the killing AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iranian worshippers attend a mourning prayer for Soleimani in Iran's capital Tehran AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Kashmiri Shiite Muslims shout anti American and anti Israel slogans during a protest AP US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iranian worshipers chant slogans during Friday prayers Reuters US airstrike kills Iran's Qassem Soleimani: Fallout in pictures A protest against the USA, in Islamabad, Pakistan EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iranians burn a US flag in Tehran EPA US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Supporters of the National Council of Resistance of Iran in Germany (NWRI) protest outside Iran's embassy in Berlin, Germany Reuters US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Supporters of the National Council of Resistance of Iran in Germany (NWRI) protest outside Iran's embassy in Berlin Reuters US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iranian worshippers in Tehran AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Vehicles of the United Nations Interim Forces in Lebanon (UNIFIL) patrol a road in the southern Lebanese town of Kfar Kila near the border with Israel. Following morning's killing of Major General Qasem Soleimani, Lebanon's Iran-backed Hezbollah movement called for the missile strike by Israel's closest ally, to be avenged AFP via Getty US airstrike kills Iran's Qassem Soleimani: Fallout in pictures Iranian women take to the streets in Tehran EPA

Furious, the US president said his troops would not leave without being paid for its military investments in Iraq over the years and warned that he would hit Baghdad with economic penalties if forces did have to withdraw.

“We will charge them sanctions like they’ve never seen before ever. It’ll make Iranian sanctions look somewhat tame,” Mr Trump told reporters.

“If there’s any hostility, that they do anything we think is inappropriate, we are going to put sanctions on Iraq, very big sanctions on Iraq.”

(President’s official website/AFP) (Official President's website/AFP)

He added: “We’re not leaving until they pay us back for it.”

US Secretary of State Mike Pompeo reiterated that the US military may well strike more Iranian leaders if the Islamic Republic retaliates but he tried to downplay Trump’s threat to attack Iranian cultural sites, which could be illegal under international and US military law.

Mr Pompeo said only that any strikes would be legal.

“We’ll behave inside the system,” he added. “We always have, and we always will.”

Washington has scrambled to contend with the repercussions of the surprise killing of Soleimani, which was so contentious it has been described as a declaration of war.

Tehran has already said it will no longer abide by any limits of an international nuclear deal including restrictions on the enrichment of uranium, or research and development, in a devastating blow to the 2015 deal brokered with the US, UK, France, China, Russia and Germany.

Hours later Iraq’s parliament voted to oust US and other foreign troops fighting the Islamic State.

Soleimani, 62, who oversaw the training and financing of Iran’s feared proxy groups like the Popular Mobilisation Forces in Iraq and the Lebanese Military group Hezbollah, was responsible for the deaths of hundreds of Americans, as well as overseeing the killing of civilians and sieges in places like Syria.

But to his supporters in the region, he was a key figurehead in the battle against western imperialism. His death has only galvanised that image.

In Iran on Monday Iran’s Supreme Leader Ayatollah Ali Khamenei, who had a close relationship with Soleimani, wept as he prayed over the caskets of the commander, while crowds chanted “death to America” outside.

Soleimani’s successor, Esmail Qaani stood near Khamenei’s side, as did Iranian President Hassan Rouhani and other top leaders in the Islamic Republic.

The leader of the Palestinian militant group Hamas that governs the blockaded Gaza Strip was also in attendance.

Ismail Haniyeh, in an address to Iranian mourners, described Soleimani, as “the martyr of Jerusalem.”

Soleimani’s daughter Zeinab also spoke reiterating that her father’s killing will only “resurrect” the cause.

“Crazy Trump, don’t think that everything is over with my father’s martyrdom,” she said.

Qaani, the new head of the Quds force, made his own threat in an interview with Iranian state television also aired on Monday.

“God the Almighty has promised to get his revenge, and God is the main avenger. Certainly, actions will be taken,” he said.

Mourners in Tehran gather to pay homage to top Iranian military commander Qasem Soleimani, after he was killed in a US strike in Baghdad last week (ATTA KENARE/AFP via Getty Images)

He added Iran would continue Soleimani’s path and said, “the only compensation for us would be to remove America from the region.”

Over the last few days, mass funerary processions have taken place across the country, which up until recently had been gripped by nationwide anti-government protests during which over 300 people were reportedly killed.

The commander’s assassination appears to have temporarily silenced that anger and instead has seen politicians and leaders across the Islamic Republic’s political spectrum take part in the mourning.

It has also united factions in Iraq against the US: rival Shi’ite leaders, including ones opposed to Iranian influence, have united in calling for the expulsion of American troops.

Mr Trump’s decisions and statements have been met with shock and confusion from his western allies.

(Iran Press TV via AP (Iran Press TV via AP)

Germany’s foreign minister Heiko Maas told Deutschlandfunk radio on Monday it’s “not very helpful” to threaten sanctions on Iraq, and said together with other European powers they would talk to Iran to try to salvage the nuclear agreement.

France’s Finance Minister Bruno Le Maire meanwhile said that the tensions in the Middle East would only serve the Islamic State and “increase the terrorist threat over France and Europe.”