United States military leaders on Thursday threatened a retaliatory strike against Iranian-backed Shia militia in Iraq, saying they know who launched the rockets in Iraq that killed and wounded US and coalition troops.

US President Donald Trump gave the Pentagon the authority to respond after a rocket barrage killed two US troops and a British soldier, again raising tensions with Iran after the two countries came to the brink of war earlier this year.

More:

Military leaders said they know who launched the rockets and the Shia militia group responsible will be held accountable.

"I have spoken with the president. He's given me the authority to do what we need to do, consistent with his guidance. And, you know - if that becomes the case ..." defence chief Mark Esper told reporters at the Pentagon, adding he and Trump had a "good conversation".

Asked what he meant, Esper suggested he was not going to telegraph any US response.

Asked if the US response could include strikes inside Iran, Esper said: "I'm not going to take any option off the table right now, but we are focused on the group - groups - that we believe perpetrated this in Iraq.

"We're going to take this one step at a time, but we've got to hold the perpetrators accountable," Esper said. "You don't get to shoot at our bases and kill and wound Americans and get away with it."

'Indirect fire'

Two US troops and one British service member were killed and 18 other personnel wounded at Camp Taji north of Baghdad on Wednesday night in the rocket fire.

US Marine General Kenneth McKenzie earlier did not blame any specific militia, but noted only Iran-backed Kataib Hezbollah had been known to wage such attacks on coalition forces in the past.

"While we are still investigating the attack, I will note that the Iranian proxy group Kataib Hezbollah is the only group known to have previously conducted an indirect fire attack of this scale against US and coalition forces in Iraq," McKenzie told a US Senate hearing on Thursday.

The attack marked a dramatic uptick in violence less than three months after rockets killed a US contractor in northern Iraq, unleashing a round of tit-for-tat attacks between Washington and Tehran on Iraqi soil.

Within hours of the attack on the Taji air base north of Baghdad - the deadliest in years on a base used by US forces in Iraq - an air strike killed more than two dozen Iran-aligned fighters in neighbouring Syria.

Fearing an even bloodier flare-up this time, Iraqi officials and the United Nations were quick to condemn the deaths.

'Terrorist attack'

Iraqi President Barham Salih and parliament speaker Mohammed al-Halbousi condemned the "terrorist attack" that targeted "Iraq and its security".

The UN mission in Iraq called for "maximum restraint on all sides".

"These ongoing attacks are a clear and substantial threat to the country, and the risk of rogue action by armed groups remains a constant concern," the UN mission said. "The last thing Iraq needs is to serve as an arena for vendettas and external battles."

The rocket attack was the 22nd against US military interests in the country since late October, an Iraqi military commander said.

In late December, the US accused Iran-aligned faction Kataib Hezbollah of killing a US contractor at a base in northern Iraq. It responded with air strikes in western Iraq that killed 25 of the group's fighters.

Days later, a US drone killed senior Iranian commander Qassem Soleimani and militia commander Abu Mahdi al-Muhandis near Baghdad airport.

Iran then launched its own strikes on a western Iraqi base, leaving dozens of US troops suffering from brain trauma.

Iraq has years of close ties with both Iran and the US, and has been put in an increasingly difficult position by the spiralling tensions between the two.

In January, Iraqi lawmakers voted to oust all foreign troops from Iraq in reaction to the killing of Soleimani and Muhandis.

Some 5,200 US troops are stationed in Iraq as part of the coalition formed in 2014 to fight the armed group ISIL (ISIS).

While ISIL has lost all of the vast territory it once held in Iraq and Syria, sleeper cells remain capable of carrying out attacks on both sides of the border.