Supporters of Iranian-backed Iraqi paramilitary groups who stormed the U.S. embassy's perimeter and hurled rocks in two days of protests withdrew on Wednesday after Washington dispatched extra troops and threatened reprisals against Tehran.
The demonstrators, angry at U.S. airstrikes against the Tehran-backed Kataib Hezbollah group that killed at least 25 people, threw stones at the building while U.S. forces stationed on the rooftops fired tear gas to disperse them.
But by mid-afternoon, most appeared to have obeyed a call to withdraw, issued by the Popular Mobilization Forces (PMF) umbrella group of mainly Shi'ite militia, which said the demonstrators' message had been heard.
Young men used palm tree branches to sweep the street in front of the embassy compound, while others packed up equipment and vans arrived to take people away. Some left to set up a protest camp in front of a nearby hotel.
Iraq's military said all protesters had left by the evening.
The U.S. Embassy in Baghdad said on Wednesday that all public consular operations were suspended in the wake of the attacks.
"Due to militia attacks at the U.S. Embassy compound, all public consular operations are suspended until further notice. All future appointments are canceled. U.S. citizens are advised to not approach the embassy," it said in a statement.
U.S. Secretary of State tweeted that he spoke on Wednesday with Iraqi Prime Minister al-Mahdi, who agreed that Iraq would continue to uphold its responsibility to "keep U.S. personnel secure" and would move the Iran-backed attackers away from the embassy.
Earlier in the day, Pompeo postponed his trip to Ukraine and four other countries, citing the Iraq attacks. Pompeo was to arrive in Ukraine late Thursday in his first visit to the country at the center of President Donald Trump's impeachment, then on to Belarus, Kazakhstan, Uzbekistan, and Cyprus.
He delayed the trip "to continue monitoring the ongoing situation in Iraq and ensure the safety and security of Americans in the Middle East," State Department spokeswoman Morgan Ortagus said Wednesday. She said he intends to reschedule soon.
The protests mark a new turn in the shadow war between Washington and Tehran playing out across the Middle East.
The unrest followed U.S. air raids on Sunday against Kataib Hezbollah bases in retaliation for missile attacks that killed a U.S. contractor in northern Iraq last week.
On Tuesday, crowds chanted 'Death to America!', lit fires, and smashed surveillance cameras. They breached an outer perimeter of the embassy but did not enter the main compound.
The huge embassy, built along the banks of the Tigris River in central Baghdad's fortified "green zone" during American occupation following the 2003 invasion that toppled Saddam Hussein, is the biggest U.S. diplomatic mission in the world.
Washington said its diplomats were safe and was rushing hundreds of extra troops to the region.
The embassy said all public consular operations were suspended and all future appointments canceled.
The anti-American action comes after months of protests in Iraq against the government and the Iran-backed militias which support it. Many Iraqis complain their country has become a battlefield for a proxy war for influence between Washington and Tehran, and their leaders are too beholden to outside powers.
Iraq's government has long faced frictions in its close relations with the two foes. Trump spoke to Prime Minister Adel Abdul Mahdi on Tuesday and demanded Iraq protect the embassy.
Iran's Supreme Leader Ayatollah Ali Khamenei on Wednesday condemned the U.S. attacks. Iran summoned a Swiss envoy, who represents U.S. interests in Tehran, to complain about what it described as "warmongering" words from Washington.
Trump accused Iran of orchestrating the violence.
U.S. officials said 750 extra troops would initially be based out of Kuwait and as many as 4,000 troops could be sent to the region in the coming days.
More than 5,000 U.S. troops are stationed in Iraq supporting local forces. The airstrikes have galvanized calls inside Iraq to expel them.
Many in the crowd outside the embassy said ending Washington's presence in Iraq was their main goal.
Despite decades of enmity between Iran and the United States, Iran-backed militias and U.S. forces found themselves on the same side during Iraq's 2014-2017 war against Islamic State fighters, with both powers helping the government recapture territory from militants who had overrun a third of Iraq.
Since then, U.S. troops have yet to leave, while the Iran-backed militias have been incorporated into the security forces.
Prime Minister Adel Abdul Mahdi, who has announced plans to step down in the face of anti-government protests in which more than 450 people were killed, is backed by Iran and its allies.
The militia may have decided to pull back from the embassy to avoid making him look weak or to avert clashes with government forces.
Overnight, demonstrators had pitched tents and camped outside the embassy walls, then brought food, cooking equipment and mattresses during the morning, indicating plans to stay before the withdrawal call.
"Our sit-in is eternal, until this devil's den is closed off forever, but don't give anyone an excuse to make your protest violent. Don't clash with security," one protest leader told the crowd from a stage erected at the embassy before the departure.
Young men, some in fatigues, waved militia flags and chanted "Death to America" as Apache helicopters circled above.
The embassy's outer walls bore scorch marks and graffiti.
"Iraq is not safe for America and its followers," one read.
—CNBC and The Associated Press contributed to this report.