BAGHDAD — Embattled Iraqi Prime Minister Nouri al-Maliki announced late Thursday that he was relinquishing his post to his nominated replacement, ending a political deadlock that has plunged the country into uncertainty as it fights a Sunni militant insurgency.

Standing alongside senior members of his party, including rival Haider al-Abadi, Maliki said he was stepping aside in favor of his “brother” in order to “facilitate the political process and government formation.”

Maliki had been struggling for weeks to stay on for a third four-year term as prime minister amid an attempt by opponents to push him out, accusing him of monopolizing power and pursuing a fiercely pro-Shiite agenda that has alienated the Sunni minority. The United States, the U.N. and a broad array of political factions in Iraq had backed Abadi, saying only a new leader could unify a country under siege from Sunni extremists of the Islamic State group who have captured large swaths of Iraqi territory.

Maliki said his decision to throw his support behind Abadi reflected a desire to “safeguard the high interests of the country,” adding that he would not be the cause of any bloodshed. “My position is your trust in me, and no position is higher than your trust,” he declared in a televised address.

Maliki’s refusal to give up his position after eight years in power had provoked a political crisis that escalated this week in Baghdad, where armed guards patrolled most major bridges, intersections and roadways.

The pressure intensified when his Shiite political alliance backed Abadi to replace him, and President Fouad Massoum nominated Abadi on Monday to form the next government. Maliki refused to step aside, threatening legal action against the president for what he said was a violation of the constitution.

But in a meeting of his party earlier Thursday, Maliki agreed to endorse Abadi as the next prime minister, two senior lawmakers from his State of Law parliamentary bloc — Hussein al-Maliki and Khalaf Abdul-Samad — told the Associated Press.

The lawmakers said Maliki also agreed to drop a suit before the constitutional court challenging Abadi’s nomination.

The White House commended Maliki for backing Abadi and expressed hope that the power shift “can set Iraq on a new path and unite its people” against the threat from Islamic militants, national security adviser Susan Rice said in a statement.

U.S. Secretary of State John Kerry said the move “sets the stage for a historic and peaceful transition of power in Iraq. We urge Mr. Abadi and all Iraqi leaders to move expeditiously to complete this process, which is essential to pulling the country together and consolidating the efforts of Iraq’s many diverse communities against the common threat posed by the Islamic State …”

The United Nations special representative for Iraq, Nickolay Mladenov, also welcomed the move, saying it “demonstrates statesmanship and a commitment to the democratic process and the constitution.”

Maliki had grown increasingly isolated as he was deserted not only by his Shiite allies but also top ally Iran, the United States and the U.N.-backed Abadi, who has 30 days to put together a cabinet for parliament’s approval.

The U.N. Security Council urged Abadi to work swiftly to form “an inclusive government that represents all segments of the Iraqi population and that contributes to finding a viable and sustainable solution to the country’s current challenges.”

Iraqis of all sects welcomed Thursday’s announcement.

“Now, all we want is a government that respects the people and does not discriminate against them,” said Youssef Ibrahim, 40, a Sunni government employee in Baghdad.

Adnan Hussein, 45, a Shiite in Sadr City, said he believes Maliki stepped down “because he came under enormous pressure and threat from inside and outside Iraq … The years he ruled were the worst in Iraq’s history and he bears that responsibility.”

The U.S. and other countries have been pushing for a more representative government that will ease anger among Sunnis, who felt marginalized by Maliki’s administration, helping fuel the dramatic sweep by the Islamic State extremist group that has seized large swaths of territory of northern and western Iraq since June.

Widespread discontent with Maliki’s rule has reached the point where both Saudi Arabia and Iran — regional rivals often bitterly divided over Iraq — have expressed support for Abadi. The United States, the European Union and the United Nations have also offered support for new leadership.

Maliki “defamed his image by threatening to use force or to complain to the federal court,” said Aziz Jaber, a professor of political science at Baghdad’s Mustansiriyah University. “The main reason al-Maliki was forced to accept this new reality is the stance of the Marjayah (Iraq’s elite Shiite clerics) and the rare agreement of Iran and Saudi Arabia that he should leave.”

The extremist Islamic State group’s lightning advance across much of northern and western Iraq has driven hundreds of thousands of people from their homes since June, and last week prompted the U.S. to launch aid operations and airstrikes as the militants threatened religious minorities and the largely autonomous Kurdish region.

The U.N. on Wednesday declared the situation in Iraq a “Level 3 Emergency” — a development that will allow for additional assets to respond to the needs of the displaced, said Mladenov, pointing to the “scale and complexity of the current humanitarian catastrophe.”

The decision came after some 45,000 members of the Yazidi religious minority were able to escape from a remote desert mountaintop where they had been encircled by Islamic State fighters, who view them as apostates and had vowed to kill any who did not convert to Islam.

The U.N. said it would provide increased support to the Yazidis and to 400,000 other Iraqis who have fled since June to the Kurdish province of Dahuk. A total of 1.5 million people have been displaced by the fighting.

The United States has been carrying out airstrikes in recent days against Islamic State fighters, helping fend off their advance on Kurdish regions.

French President Francois Hollande on Thursday confirmed the “imminent delivery of military equipment” to Kurdish forces in a phone call with Massoum, Hollande’s office said. It did not specify the type or amount of equipment.

The statement said Paris would also provide more humanitarian aid. France has sent dozens of tons of aid in several deliveries this week.