BAGHDAD - Escalating tensions between the United States and Iran have raised the prospect that Iraq could again became the terrain on which these two powers pursue their shadow war and a staging ground for attacks on American and allied forces in the region.

But recent developments suggest that the government in Baghdad is trying to clip the wings of the powerful Iran-aligned militias operating in Iraq, just as Tehran is looking for its proxies and allies in the Middle East to intensify the pressure on U.S. interests.

Iraqi officials are worried that their country could get sucked into the conflict, with concerns spiking after a May 14 drone strike on a pipeline in neighboring Saudi Arabia. The officials were embarrassed to learn that the attack had not come from Iran-backed rebels in Yemen, who had claimed responsibility for the strike, but from Iraqi territory, said lawmakers and Western officials who described the fallout.

"The prime minister was very angry," said one, speaking on condition of anonymity because of the sensitivity of the issue.

A tense meeting followed between Iraqi Prime Minister Adel Abdul Mahdi and Faleh al-Fayyadh, chairman of the coalition of mostly Shiite Muslim paramilitaries, some aligned with Iran, known as the Popular Mobilization Forces, according to several people familiar with the meeting.

Abdul Mahdi demanded, "Take care of it," one of those people said.

After a devastating attack two weeks ago on oil installations in eastern Saudi Arabia by a combination of drones and cruise missiles, again claimed by Yemeni rebels, U.S. officials quickly blamed Iran for the strike. It was notable that U.S. and Iraqi officials said they were relatively confident that this time the staging ground was not Iraq.

"Notice the confidence," said the Iraqi lawmaker. "The prime minister immediately issued a statement denying it had come from Iraq. Unlike the earlier strike, where he faced embarrassment, this time he was sure."

The backlash against the earlier attack "made it uncomfortable for the [militias] to do it again," said Michael Knights, a senior fellow at the Washington Institute. "Iraq dodged a bullet here, and it wasn't luck. It was because a spotlight got shone on the May 14 strike."

Iraqi lawmakers fear that attacks launched from their soil would not only inflame regional tensions but could provoke reprisals against targets inside their country, drawing Iraq into another ruinous conflict. As the head of a divided government, Abdul Mahdi's hand remains weak.

In a sign of Baghdad's delicate diplomacy, Iraqi President Barham Salih met separately this week in New York with President Donald Trump and Iranian President Hassan Rouhani.

Abdul Mahdi, meantime, was received by Saudi Crown Prince Mohammed bin Salman in Riyadh to discuss this month's attacks on the oil installations.

In comments made alongside Trump, Salih described efforts to bring the country's paramilitaries to heel as a "work in progress."

Militiamen from the PMF still operate with relative autonomy across much of Iraq. A July 31 deadline for their formal incorporation into the Iraqi army has been extended, with patchy results.

"It's not just a military organization. It's also a political, social and economic network, and you can't just integrate that easily," said Renad Mansour, a research fellow at the London-based Chatham House think tank.

But for the PMF, known in Arabic as the Hashd, there are also advantages to becoming part of Iraq's official security forces. That status can legitimize the power of groups within the paramilitary coalition. It also "gives formal cover," Mansour said. "It gives groups the chance to operate without being attacked from outside."

The Iranian-backed militias played a pivotal role in ousting the Islamic State from Iraq two years ago. But in the years after the U.S.-led invasion of Iraq in 2003, Iran also sponsored militia violence against American troops, flooding the country with powerful roadside bombs that killed hundreds.

In recent months, elements within the PMF have repeatedly been blamed for rocket attacks on U.S. forces and their Iraqi allies, with crude projectiles striking the area of military bases. Early Tuesday, a rocket landed inside the sprawling U.S. Embassy complex in Baghdad's Green Zone and another nearby in an empty lot.

The purpose of these strikes, experts say, was to harass but not provoke. They were meant as reminders that the militias have the ability to launch more damaging strikes in the event of escalation.

The broader regional tensions have also aggravated divisions within the PMF's leadership.

After suspected Israeli airstrikes this summer targeted militia bases, the PMF's powerful deputy leader, Abu Mahdi al-Muhandis, who is close to parts of the Iranian establishment, explicitly blamed both the United States and Israel. Fayyadh disputed that accusation, saying Muhandis didn't speak for the paramilitary coalition.

"How they handle this now will be critical," said another Iraqi official, speaking on condition of anonymity because he was not authorized to discuss the issue. "The Hashd is a time bomb, and the prime minister needs to come down against them, but he won't be able to do so for long. It depends on how Fayyadh can control them."

Ihsan al-Shimari, head of the C and a former adviser to Abdul Mahdi's predecessor, Haider al-Abadi, said that tensions were likely to continue while Iranian-backed groups operated with a degree of autonomy outside of the state.

“If these factions do not obey and commit themselves to the Iraqi government, the Iraqi situation will be very difficult,” he said.