Iraq's parliament elected a senior Kurdish lawmaker president on Thursday, a significant step in a delayed process to create a government capable of uniting the country and countering insurgents threatening to march on Baghdad.
Visiting UN Secretary-General Ban Ki-moon said Iraq's very survival as a nation was at risk and told politicians to drop ethnic and sectarian differences and form an inclusive government to combat the nation's "existential threat".
Iraq's politicians have been in deadlock over forming a new government since an election in April. The next step, choosing a prime minister, may prove far more difficult.
Shi'ite Prime Minister Nuri al-Maliki has ruled since the election in a caretaker capacity, defying demands from minority Sunnis and Kurds that he step aside for a less divisive figure.
Even some fellow Shi'ites oppose his bid for a third term.
Critics say Maliki has stirred up sectarian tensions that have worsened since the Sunni insurgent group Islamic State swept through north and west Iraq last month, seizing large swathes of territory and declaring a "caliphate".
"Iraq is facing an existential threat but it can be overcome through the formation of a thoroughly inclusive government - a government that can address the concerns of all communities, including security, political, social and economic matters," Ban told a news conference with Maliki in Baghdad.
The UN chief went from the capital to the holy Shi'ite city of Najaf to meet Iraq's top cleric.
Grand Ayatollah Ali al-Sistani has assumed his most active role in politics in a decade, demanding a new government be formed without delay. The 83-year-old's renewed activism could hasten the end of Maliki's political ambitions.
"His Eminence underscored that the fight against the Islamic State and other armed groups should be exclusively conducted by the Iraqi security forces and only within the framework of the constitution," Ban told reporters after meeting Sistani.
The comments appeared aimed at discouraging the activities of Shi'ite militias that operate independently of the Iraqi army, some of which have abducted Sunnis they suspect of militancy. Many later turn up dead.
"We also discussed the ongoing political process of government formation," Ban said.
As Kurdish lawmaker Fouad Masoum was being elected president in Baghdad, a deadly gun and bomb attack on a bus carrying prisoners to the capital showed the security challenge facing the country.
Fifty-two prisoners and nine policemen were killed as the bus, travelling from a military base in the town of Taji, was hit by roadside bombs. Gunmen then opened fire, justice ministry sources said.
The Interior Ministry said the attackers were terrorists - the word usually used to describe Sunni insurgents.
In June, 69 prisoners were killed while being transported to a jail in Baghdad. The official account was that militants had attacked the convoy, killing 10 prisoners and one policeman.
But a police captain, a second police officer and a senior local official told Reuters no attack took place, and that police had killed the 69 men.
In northern Iraq, Kurdish Peshmerga fighters, who have for weeks been battling Islamic State militants in Jalawla, 115 km (70 miles) northeast of Baghdad, took complete control of the town after overnight clashes.
Jalawla lies in disputed territory and is one of several towns where Iraqi troops and Kurdish Peshmerga regional guards have faced off, asserting their competing claims over the area.
In June, Kurdish forces took control of the oil city of Kirkuk after government troops abandoned their posts in the face of the Sunni Islamist rebel march towards Baghdad.
Kurds have long dreamed of taking Kirkuk and its huge energy reserves. They regard the city, just outside their autonomous region, as their historical capital.