BAGHDAD (Reuters) - Iraqi Prime Minister Adel Abdul Mahdi on Wednesday urged Washington and Tehran to show restraint following Iranian missile attacks on U.S. troops in Iraq as he sought to deal with the two long-standing foes who are also Baghdad’s main allies.

FILE PHOTO: Iraqi Prime Minister Adel Abdul Mahdi speaks during a symbolic funeral ceremony of Major General Ali al-Lami, who commands the Iraqi Federal Police's Fourth Division, who was killed in Salahuddin, in Baghdad, Iraq October 23, 2019. REUTERS/Khalid al-Mousily/File Photo

Abdul Mahdi rejected any violation of Iraqi sovereignty or carrying out of attacks within its borders, and said he was trying to calm the situation.

Iranian forces fired missiles from Iran at two military bases in Iraq housing U.S. troops on Wednesday in retaliation for Washington’s killing of Iranian General Qassem Soleimani. The United States is weighing how to respond.

“We call on all sides to practice self-restraint, keep a cool head, adhere to international agreements, respect the Iraqi state and its government’s decisions, and help it contain and get past this dangerous crisis that threatens it, the region, and the world with a devastating all-out war,” Abdul Mahdi said.

He used similar words after a drone strike ordered by U.S. President Donald Trump killed Soleimani and Iraqi militia leader Abu Mahdi al-Muhandis in Baghdad last Friday. He now faces a tricky balancing act.

Iranian-backed militias and a U.S.-led military coalition have both helped Iraq defeat Islamic State militants who overran a third of its territory in 2014. They have also been embroiled in a proxy conflict in Iraq and elsewhere in the region.

Indicating the Baghdad government’s dilemma, Abdul Mahdi’s spokesman said that shortly after midnight on Wednesday, it had received a message from Iran that its response to Soleimani’s killing had started or was about to start.

Tehran told Abdul Mahdi it would only target locations where U.S. forces were present but did not specify the locations, he said.

Then Abdul Mahdi received a call from the United States while missiles were falling on the American wing of the air base in Anbar province and an air base in Erbil, the spokesman said.

SHI’ITE WELCOME, SUNNI DISQUIET

Some Shi’ite militia leaders welcomed the Iranian attack.

Rival leaders from the Shi’ite majority, including ones opposed to Iranian influence, had united after the killing of Soleimani in calling for the expulsion of the 5,000 U.S. troops stationed in Iraq. Parliament on Sunday also passed a resolution demanding they leave.

“The American aggression provided justification for the Iranian response,” the Fatih alliance representing the militias in parliament said.

Iran-backed Iraqi militia commander Qais al-Khazali went further and threatened an Iraqi attack as well, saying Tehran had paved the way.

“The initial Iranian response to the assassination of the martyred commander Soleimani has happened. Now it is time for the initial response to the assassination of the martyred commander Muhandis,” he said.

Many Iraqis, including opponents of Soleimani, are angry with Washington for killing him and Muhandis on Iraqi soil, potentially dragging their country into another conflict.

However, Sunni Arab and Kurdish minorities fear the expulsion of the U.S.-led coalition will leave Iraq vulnerable to an insurgency, undermine security, and further empower the Iranian-backed militias.

Lawmakers from both groups boycotted Sunday’s parliament session.

On Wednesday, Parliament Speaker Mohammed al-Halbousi, the top Sunni politician, called for “taking the necessary measures to preserve Iraqi sovereignty”.

Iraqi President Barham Salih, a Kurd, said the coalition presence was a domestic affair after Iran called on the United States to leave Iraq. He said Iraq should be kept out of a new war.

The semi-autonomous Kurdistan Region of Iraq’s leaders said the coalition’s presence was vital for fighting Islamic State and called on its member states to stay. They asked Washington and Tehran to keep the region out of their own conflict.

“The Kurdistan Region views the support of the International Coalition in Iraq and the Kurdistan Region in confronting terror as a necessity, the regional president, prime minister, and parliament speaker said in a joint statement.