Protesters in Iraq have dealt a symbolic blow to US prestige by storming the American embassy in Baghdad, trapping diplomats inside while chanting “Death to America” and slogans in support of pro-Iranian militias.

In a humiliating day for Washington, hundreds of demonstrators 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 lobbed 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. They made their way to the embassy, climbing walls and hurling stones. US guards responded with tear gas but did not open fire.

Donald Trump accused Iran of orchestrating the day-long attack, which followed US airstrikes on Sunday against three camps in Iraq and two in Syria. The bases belonged to the Iran-backed Kata’ib Hezbollah militia group, which is formally part of the Iraqi army. At least 25 fighters were killed and dozens injured.

Facebook Twitter Pinterest Members the Hashed al-Shaabi, a mostly Shiite network of local armed groups trained and armed by powerful neighbour Iran, smash the bullet-proof glass of the US embassy’s windows in Baghdad. Photograph: Ahmad Al-Rubaye/AFP via Getty Images

US officials said the raids were carried out to deter future acts of aggression following a rocket attack on Friday by the group against a US base in Kirkuk, in which one US contractor was killed and four Americans were injured. President Trump approved the operation on Saturday.

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.

An embassy spokesperson told CNN that the chief of the US mission in Iraq, Matthew Tueller, was away on a scheduled vacation and had left Baghdad a week ago. The embassy was under lockdown but had not been evacuated, the spokesperson said, with diplomats sheltering in a safe-room.

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 insouciantly with an official US embassy sign.

Former foreign service staff compared the chaotic scenes to the ransacking in 1979 of the US embassy in Tehran, which saw 52 US citizens 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 survived intact.

Facebook Twitter Pinterest Iraqi protesters gather inside the security office at the entrance of the US embassy building in the capital Baghdad during a protest by Iraqis against the weekend’s air strikes by US planes on several bases belonging to the Hezbollah brigades near Al-Qaim, an Iraqi district bordering Syria. Photograph: Ahmad Al-Rubaye/AFP via Getty Images

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 brought about few tangible diplomatic results and has taken relations with Iraq to a new low.

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’s 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.

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.