Donald Trump has directly threatened Iran, saying it will pay a “very big price” for any US lives lost or facilities damaged in the wake of a mob attack on the American embassy in Baghdad.

In a humiliating day for Washington, hundreds of supporters of Iraqi Shia militia, many wearing military fatigues, besieged the US compound, at one point breaching the main gate and smashing their way into several reception rooms. They lit fires, battered down doors and threw bricks at bulletproof glass.

The rampage was carried out with the apparent connivance of Iraqi security forces who allowed protesters inside the highly protected Green Zone. US guards responded with teargas but did not open fire.

Facebook Twitter Pinterest Protesters lit fires at the US compound. Photograph: Thaier Al-Sudani/Reuters

After declaring the embassy safe, Trump tweeted: “Iran will be held fully responsible for lives lost, or damage incurred, at any of our facilities. They will pay a very BIG PRICE! This is not a Warning, it is a Threat. Happy New Year!”

The Trump administration’s declared policy has been to treat any attack on US interests by Iranian proxies as an attack by Iran itself. On Sunday, the US conducted air strikes on bases belonging to the Kata’ib Hezbollah militia group, which is formally part of the Iraqi army. The group’s attacks on Iraqi bases hosting coalition forces culminated in the death of a US contractor and injuries to at least four American soldiers in Kirkuk on Friday.

At least 25 fighters were killed and dozens injured in the US strikes. The embassy attack followed.

Instead of advancing US goals, the airstrikes appear to be the latest in a series of foreign policy blunders in the Middle East. Iraq’s government furiously condemned them, while pro-Iranian militias promised further attacks against American targets, with the goal of expelling US forces.

“Iran killed an American contractor, wounding many. We strongly responded, and always will,” Trump tweeted. “Now Iran is orchestrating an attack on the US embassy in Iraq. They will be held fully responsible.”

The US embassy denied earlier reports from Iraq’s foreign ministry that the ambassador and his staff were hastily evacuated, as protesters surged towards the building.

Facebook Twitter Pinterest US embassy security staff seen through a window as protesters and militia fighters gather outside. Photograph: Thaier Al-Sudani/Reuters

A state department spokesperson told the Guardian the chief of the US mission in Iraq, Matthew Tueller, was away on a scheduled vacation and left Baghdad a week ago. The embassy was under lockdown but had not been evacuated, officials said, with diplomats sheltering in a “safe room”.

“The Iranian-backed demonstrations in front of the US embassy should not be confused with the Iraqi protesters who have been in the streets since October to decry the corruption exported to Iraq by the Iranian regime,” the spokeswoman said.

“We have made clear the United States will protect and defend its people, who are there to support a sovereign and independent Iraq. We are closely monitoring the situation in Iraq and call on the government of Iraq to protect our diplomatic facilities per their obligations.”

Video from the scene showed thick grey smoke engulfing the compound against a backdrop of wailing from an emergency siren. Protesters shouted “no, no, America!” and “no, no, Trump!”, and “death to America!”. By nightfall fires were still burning. One masked man walked off with an official US embassy sign.

The US state department said personnel at the embassy were safe and there were no plans to evacuate. “Our first priority is the safety and security of US personnel,” a spokesperson said in a statement.

“US personnel are secure and there has been no breach,” the spokesperson said. “There are no plans to evacuate Embassy Baghdad.”

The US defence secretary, Mark Esper, announced that he authorized the immediate deployment of about 750 soldiers to the Middle East. He said additional troops are prepared to deploy over the next several days.

Former foreign service staff compared the chaotic scenes to the ransacking in 1979 of the US embassy in Tehran, when 52 US citizens were taken hostage. Tuesday’s events, however, were not on the same dramatic scale. There was no loss of life and most of the embassy building was not breached.

Nonetheless, the prospect of a worsening conflict between US forces and Iranian proxies in Iraq looms large. The Trump administration’s policy of piling sanctions and economic pressure on Tehran appears to have delivered few tangible diplomatic results and has taken relations with Iraq to a new low.

Russia and Iran condemn US airstrikes in Iraq and Syria Read more

Iraq’s prime minister, Adel Abdul Mahdi – an ally of both Iran and Washington – vowed on Tuesday to protect the safety and security of US personnel. After doing little initially to halt the violence, Iraqi security forces turned up in force in the afternoon and formed a protective line between angry crowds and US guards.

The US secretary of state, Mike Pompeo said the US would “protect and defend its people” in a phone call with Abdul Mahdi. The viability of the US diplomatic mission in Baghdad – its largest in the world – is now an open question, as demonstrators set up tents outside its perimeter.

Many of the protesters had come from funerals held in Baghdad for some of the dead militia fighters. They were carrying flags belonging to Kata’ib Hezbollah and to Hashd al-Shaabi (Popular Mobilization Forces), a powerful paramilitary group of which Kata’ib Hezbollah is a part.

Facebook Twitter Pinterest Mourners carry the coffin of Iran-backed Popular Mobilisation fighters killed in the U.S. airstrike in Qaim, during their funeral in Najaf, Iraq. Photograph: Anmar Khalil/AP

Qais al-Khazali, the leader of the Iranian-backed Asa’ib Ahl al-Haq militia, and many other senior militia leaders were among the demonstrators. On Monday, Iran condemned the US strikes as “terrorism”. Russia complained it had not been given advance warning.

Street protests take place regularly in the Iraqi capital. In recent months, security guards have shot dead more than 450 people protesting against rampant government corruption and the growing influence of Iranian-backed groups, including Kata’ib Hezbollah.