Iran-backed militiamen have withdrawn from the US embassy compound in Baghdad after two days of clashes with American security forces.

But US-Iran tensions remain high and could spill over into further violence.

The withdrawal followed calls from the government and senior militia leaders and ended a high-stakes two-day crisis and practical siege of the largest and one of the most heavily fortified US diplomatic missions in the world.

The attack prompted the Pentagon to send hundreds of additional troops to the Middle East.

Iraqi security forces are deployed in front of the US embassy in Baghdad
Iraqi security forces in front of the US embassy in Baghdad (Nasser Nasser/AP)

In an orchestrated assault, hundreds of militiamen and their supporters broke into the embassy compound, destroying a reception area, smashing windows and spraying graffiti on walls to protest over US air strikes against an Iran-backed militia over the weekend that killed 25 fighters.

The US blamed the militia for a rocket attack on an Iraqi military base in the northern city of Kirkuk last week that killed a US contractor.

The protesters set up a tent camp overnight and on Wednesday set fire to the reception area and threw stones at US Marines guarding the compound, who responded with tear gas.

There were no injuries on either side and no American staff were evacuated from the compound.

The Popular Mobilisation Forces, an umbrella group of state-allied militias – many backed by Iran – called on their supporters to withdraw in response to an appeal by the Iraqi government, saying “your message has been received”.

By late afternoon, the tents had been taken down and the protesters relocated to the opposite side of the Tigris River, outside the so-called Green Zone housing government offices and foreign embassies.

A man waves the Iraqi flag while Iraqi army soldiers are deployed in front of the US embassy in Baghdad
A man waves the Iraqi flag while Iraqi army soldiers are deployed in front of the embassy (Nasser Nasser/AP)

US Apache helicopters circled overhead.

“After achieving the intended aim, we pulled out from this place triumphantly,” said Fadhil al-Gezzi, a militia supporter.

“We rubbed America’s nose in the dirt.”

Kataeb Hezbollah, the Iran-backed militia targeted by the US air strikes, initially refused to leave but later bowed to demands to disperse.

The militia is separate from the Hezbollah militant group in Lebanon, though both are backed by Iran.

“We don’t care about these planes that are flying over the heads of the picketers. Neither do we care about the news that America will bring Marines,” said Mohammed Mohy, a spokesman for Kataeb Hezbollah.

“On the contrary, this shows a psychological defeat and a big mental breakdown that the American administration is suffering from,” he said, before withdrawing from the area.

The violence came as Iran and its allies across the region have faced unprecedented mass protests in recent months and heavy US sanctions have cratered Iran’s economy.

Pro-Iranian militiamen and their supporters board trucks loaded with items from a sit-in while driving away from the US embassy in Baghdad
Pro-Iranian militiamen and their supporters drive away from the US embassy in Baghdad (Nasser Nasser/AP)

Iraq has been gripped by anti-government protests since October fuelled by anger at widespread corruption and economic mismanagement, as well as Iran’s heavy influence over the country’s affairs.

Those protesters were not involved in the embassy attack.

US President Donald Trump blamed Iran for the attack on the embassy and the Pentagon dispatched an infantry battalion of about 750 soldiers to the Middle East.

A US official familiar with the decision said they would go to Kuwait.

Iran denied involvement in the attack on the embassy.

Supreme Leader Ayatollah Ali Khamenei was quoted by media as saying that “if the Islamic Republic makes a decision to confront any country, it will do it directly”.

Iran later summoned the Swiss charge d’affaires, who represents American interests in Tehran, to protest over what it said was warmongering by US officials.

Tensions have steadily risen since Mr Trump withdrew the US from Iran’s 2015 nuclear deal with world powers and embarked on a campaign of maximum pressure through economic sanctions.

Iraqi soldiers stand guard in front of the US embassy in Baghdad
Iraqi soldiers stand guard in front of the embassy (Nasser Nasser/AP)

Iran has responded by abandoning some of its commitments under the deal.

US officials have blamed Iran for the sabotage of oil tankers in the Persian Gulf and a drone attack on Saudi oil facilities in September that caused a spike in world oil prices.

But the Trump administration has not responded with direct military action, apparently fearing a wider conflict.

The US has sent more than 14,000 additional troops to the Gulf region since May in response to concerns about Iranian aggression.

At the time of the attack, the US had about 5,200 troops in Iraq, mainly to train Iraqi forces and help them combat Islamic State extremists.

The US and Iran have vied for influence over Iraq since the 2003 US-led invasion that toppled Saddam Hussein.

Iran has close ties to Iraq’s Shiite majority and major political factions, and its influence has steadily grown since then.

Iran helped to mobilise tens of thousands of mostly Shiite militiamen to battle so-called Islamic State when it stormed across northern and western Iraq in 2014 as the armed forces collapsed.

An Iraqi soldier stands guard in front of smoke rising from a fire set by pro-Iranian militiamen and their supporters in the US embassy compound in Baghdad
An Iraqi soldier stands guard in front of smoke rising from a fire set by pro-Iranian militiamen and their supporters (Nasser Nasser/AP)

The US and Iran both provided vital aid to Iraqi forces, who eventually declared victory over the extremists in December 2017.

The political influence of the Popular Mobilisation Forces has risen in recent years, and their allies dominate the parliament and the government.

That has made them the target of the anti-government protesters, who have attacked Iranian diplomatic missions and the local headquarters of parties affiliated with the militias across southern Iraq.

They have also set up a sprawling protest camp in central Baghdad, and for weeks have been trying to enter the Green Zone.

Iraqi security forces have beaten them back with tear gas and live ammunition, killing hundreds.

The militiamen and their supporters, however, were able to quickly enter the Green Zone and mass in front of the embassy, with little if any resistance from authorities.

Iraq’s government vehemently condemned the air strikes on the militia, saying it violated national sovereignty.

But Iran and its allies might have also seen the attack as a way of diverting attention from the anti-government protests.

“Iran has been trying to provoke the US into helping it solve its Iraq problem,” the Crisis Group, an international think tank, said in a briefing on the crisis.

“The Trump administration, by responding to the attacks in Kirkuk and elsewhere with air strikes, has obliged.”