US President Donald Trump has threatened Iran after blaming it for an attack on the US embassy in Iraq.
The compound in Baghdad was attacked by demonstrators furious over the deaths of militia members in US air strikes.
Mr Trump tweeted that Iran "will pay a very big price" for any damage or loss of life. "This is not a warning, it is a threat," he said.
But Iran's Supreme Leader Ayatollah Ali Khamenei responded by saying the US "can't do a damn thing".
Anti-American sentiment was widespread in Iraq, he added.
Tehran has denied that it orchestrated the attack on the Baghdad embassy.
....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!— Donald J. Trump (@realDonaldTrump) December 31, 2019
Ayatollah Khamenei's English-language Twitter account posted a translation of his remarks.
If the Islamic Republic decides to challenge & fight, it will do so unequivocally. We’re not after wars, but we strongly defend the Iranian nation’s interests, dignity, & glory.— Khamenei.ir (@khamenei_ir) January 1, 2020
If anyone threatens that, we will unhesitatingly confront & strike them.
Demonstrators regrouped outside the US embassy on Wednesday. Reports said at least one Iraqi militia had ordered its supporters to leave the area.
The protests starkly illustrate the tenuous and difficult nature of the US relationship with Iraq. The question now is whether this relationship is tenable and, if so, for how long?
The struggle against the Islamic State (IS) group obscured the basic geometry of the Iraqi government's position. It needed the US military presence to train and assist its forces. But its Shia government was closely allied with Tehran.
So developed a curious triangular relationship, with the US and Iran deeply suspicious of each other's motives and eager that their rival's influence should be reduced. Iraq steers a sometimes bumpy course between them that has got bumpier in recent weeks following a wave of domestic protest inside Iraq at the government's incompetence, which has an element of hostility to Iranian meddling too.
Iran meanwhile has built up its links to Shia militias in the country, one of which is judged by the Americans to have been responsible for the rocket attacks against its bases - hence the US air strikes. The Americans see Tehran as behind the attacks and want the Iraqi authorities to ensure the safety of US facilities.
But with the Trump administration sending out conflicting signals about its future role in the region; in part a desire to limit its involvement and in part a message of deterrence against Tehran - it is easy to be confused. And amid this confusion the danger of a direct clash between Washington and Tehran only grows.
What happened on Tuesday?
The angry crowd set an empty guard post in the street on fire and breached a reception area in the embassy compound, leading US troops to fire teargas to repel them.
"The United States will protect our people and interests anywhere they are found around the world," he wrote in a tweet.
There were no plans to evacuate the embassy, Secretary of State Mike Pompeo told Fox News. Ambassador Matthew Tueller was outside Iraq for a previously scheduled holiday and was reportedly returning to the embassy.
Iraqi soldiers and riot police were reportedly later deployed in the area, and the protest died down as night fell. Fifty people were treated for tear-gas inhalation at hospitals in Baghdad, a health ministry source told the BBC.
Mr Trump said he expected Iraqi forces to protect the embassy and its staff, and thanked Mr Abdul Mahdi for action taken during the attack.
Why was the embassy attacked?
Tuesday's protest took place after funerals were held for the militia fighters killed in the US strikes.
The militia was an Iranian-backed force, the Kataib Hezbollah militia in western Iraq and eastern Syria.
At least 25 fighters died in the US bombing of their bases on Sunday, which Washington said was a retaliation for the death of an American civilian worker killed during a rocket attack on an Iraqi military base.
Iraqi Prime Minister Adel Abdul Mahdi said the strikes had violated his country's sovereignty. The leader of the Kataib Hezbollah militia, Abu Mahdi al-Muhandis, warned that its response "would be very tough on the American forces in Iraq".
On Wednesday Iran's Supreme Leader Ayatollah Ali Khamenei "strongly condemned" the US attack on Kataib Hezbollah.
Why did the US target Kataib Hezbollah?
The US said the militia had carried out repeated attacks on Iraqi bases that host US-led coalition forces fighting the Islamic State (IS) group.
In response, it added, US forces conducted "precision defensive strikes" on Sunday against five facilities, including weapon stores and command and control locations, that would degrade its ability to conduct future attacks.
Since 2009, the US has designated Kataib Hezbollah as a terrorist organisation and listed its leader Abu Mahdi al-Muhandis as a "global terrorist".
The US defence department said the militia had a "strong linkage" with Iran's Quds Force, the overseas operations arm of the Islamic Revolution Guard Corps (IRGC), and had "repeatedly received lethal aid and other support from Iran".
The Pentagon denied reports earlier last month that the US was considering sending 14,000 more troops to the Middle East to counter Iran.