The decision by Iraq's embattled Nouri Maliki to step down as prime minister has revived hopes on for the formation of a new government that could take on a growing insurgency by Sunni militants that has engulfed much of the country.

The move, which followed weeks of international and domestic pressure, defuses a political deadlock that has plunged Iraq into uncertainty at a time of the nation's greatest turmoil since the 2011 withdrawal of US troops.

Mr Maliki announced he was giving up his post on national television late last night, standing alongside senior members of his Shiite Islamic Dawa Party, including his rival and premier-desigante Haider Abadi.

He said he was stepping aside in favour of his "brother", in order to "facilitate the political process and government formation".

Mr Abadi, a veteran Shiite lawmaker, now faces the immense challenge of trying to unite Iraqi politicians as he tries to cobble together a cabinet over the next 30 days. The country's major political factions deeply distrust each other and the army seems unable to regain territory in the north and west taken by militants from the Islamic State group.

Mr 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 monopolising power and pursuing a fiercely pro-Shiite agenda that has alienated the Sunni minority.

The United States, the UN and a broad array of political factions in Iraq had backed Mr Abadi, saying only a new leader could unify a country under siege from the Islamic State extremists who have captured large swaths of Iraqi territory.

The crisis in Baghdad escalated when Mr Maliki's Shiite alliance backed Mr Abadi to replace him, and the incumbent threatened legal action, saying the attempt to push him out was a violation of the constitution.

But in a meeting of his party earlier yesterday, Mr Maliki agreed to endorse Mr Abadi and drop the lawsuit, two senior lawmakers from his State of Law parliamentary bloc - Hussein al-Maliki and Khalaf Abdul-Samad - told The Associated Press.

The White House commended Mr Maliki's move 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.

US secretary of state John Kerry said the move "sets the stage for a historic and peaceful transition of power in Iraq".

The challenges for Mr Abadi are looming. "The problems and crises left by al-Maliki are huge," said Aziz Jaber, a political sciences professor at Baghdad's Mustansiriyah University. "The first thing al-Abadi must do is foster real national reconciliation and defuse anger among many Iraqis affected by al-Maliki's unwise policies."

The UN Security Council urged Mr 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 yesterday'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.

The US and other countries have been pushing for a more representative government that will ease anger among Sunnis, who felt marginalised by Mr Maliki's administration, which helped fuel the dramatic sweep by the Islamic State extremist group.

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

The UN this week declared the situation in Iraq a "Level 3 Emergency" - a decision that 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 UN 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 back their advance on Kurdish regions.

In Brussels, the European Union's foreign ministers held an emergency meeting today on Iraq to co-ordinate their stance on military support for the Kurds and on providing humanitarian assistance for those fleeing the fighting.

Italian foreign minister Federica Mogherini told reporters that she hopes Mr Abadi will form a new government "in the next days, not weeks".

Sign up to our free newsletters

Get the best updates straight to your inbox:
Please select at least one mailing list.

You can unsubscribe at any time by clicking the link in the footer of our emails. We use Mailchimp as our marketing platform. By subscribing, you acknowledge that your information will be transferred to Mailchimp for processing.