Nouri Maliki had been under intense pressure to make way for Haider al-Abadi. Photo: BBC/Reuters
Iraqi Prime Minister Nouri Maliki has stepped aside, ending political deadlock in Baghdad as the government struggles against insurgents.
He resigned on state TV to make way for Haider al-Abadi, who was asked by Iraq's president to form a government.
An offensive led by Islamic State (IS) rebels in the north has triggered a security and humanitarian crisis.IS, a Sunni Muslim jihadist group formerly known as Isis, seized a large band of territory across northern Iraq and Syria this summer.The resulting turmoil has driven an estimated 1.2 million Iraqis from their homes.
Appearing on state TV flanked by Abadi and other politicians from the Shia Muslim majority, Maliki spoke of the grave "terrorist" threat from IS before announcing his own exit.
"I announce before you today, to ease the movement of the political process and the formation of the new government, the withdrawal of my candidacy in favour of brother Doctor Haider al-Abadi," he said.
Analysis: Jim Muir, northern Iraq
His eight years in office, Maliki said, had been spent combating a mounting wave of terrorism and subversion. He insisted that he had stuck to the law and avoided violence even when he had come under personal attack but now, he said, he did not want to be the cause of the shedding of a single drop of blood.
There had been fears that Maliki might use the power base he built up through his control of the armed forces to stay in power.
But, with his own party and the Shia clerical establishment, not to mention influential outside powers such as Iran and America and the entire international community backing Abadi, the writing was clearly on the wall for Maliki's hopes of clinging to power.
He had been insisting that he should have the right to form the government, as leader of the biggest bloc in parliament.
But his spokesman, Ali Mussawi, told AFP news agency that Maliki was dropping his complaint against President Fuad Masum.
The resignation brought an end to eight years of often divisive rule, when Maliki's government was accused of favouring the country's Shia majority.
Abadi is one of Iraq's most senior politicians, having held several high-profile posts since returning from exile in 2003.
He is regarded by some as a moderate within Maliki's Dawa party, and has shown more of a willingness to compromise than his predecessor.
US National Security Adviser Susan Rice praised Maliki's decision to step down, describing it as a "major step" towards uniting Iraq.
Earlier, US President Barack Obama offered his support to the prime minister-designate.
"He [Abadi] still has a challenging task in putting a government together, but we are modestly hopeful that the... situation is moving in the right direction," Obama said.
Obama also paid tribute to US forces for an operation in the north of Iraq that he said has helped tens of thousands of people displaced by IS.
Many of them, mostly from the Christian and Yazidi religious minorities, were besieged on Mount Sinjar after being forced to flee their homes.
The BBC's Caroline Wyatt spent the day at a hospital in Dohuk where the doctors have been treating Yazidi refugees
Obama said US forces had helped break the siege and the situation had greatly improved.
However, the US will continue to carry out air strikes and support Iraqi and Kurdish forces fighting IS, he said.
Thousands of Yazidis have reached camps inside Iraq's Kurdish region, most with no possessions but the clothes on their backs, AFP news agency reports from Dohuk.
Conditions in the camps are spartan, with one man, Khodr Hussein, saying: "We went from hunger in Sinjar to hunger in this camp."
On Friday, the UN Security Council in New York is expected to pass a resolution aimed at punishing the recruitment and financing of foreign fighters for IS.
The BBC's correspondent at the UN, Nick Bryant, says the resolution, drafted by the UK, will come with the threat of sanctions as well as a blacklist targeting six people, including the spokesman of IS.