An onslaught on a convoy transferring inmates north of Baghdad left at least 60 dead Thursday, even as politicians and diplomats stepped up efforts to end Iraq's worst crisis in years.
Most of those killed in Taji, 25 kilometres (15 miles) north of Baghdad, were prisoners whose escort was attacked and were described by police as being mostly Sunni militants charged with terrorism.
Explosions from the attack were heard in some neighbourhoods of the capital, where UN chief Ban Ki-moon landed Thursday on an unscheduled stop in his Middle East tour.
"At least 60 people, prisoners and policemen, were killed in a suicide attack followed by several IEDs (improvised explosive devices) and shooting," an interior ministry official told AFP.
One security source said the inmates were being transferred as a precautionary measure after Taji prison was hit by mortar fire on Wednesday.
However the exact circumstances of the attack were not immediately clear, nor how many attackers were dead and how the prisoners they were apparently trying to free were killed.
The bus was believed to be transporting around 60 prisoners and medics said that some 50 of those killed in the pre-dawn attack were inmates.
Most of them were burnt beyond recognition, the medics said.
Government forces were recently accused by rights watchdogs of having executed more than 250 prisoners since June 9.
Among the allegations are that members of the Iraqi security forces shot prisoners, on the grounds they were sympathetic to advancing forces from the Islamic State (IS) jihadist group, that jails were set on fire and that grenades were tossed into cells.
Since it launched a sweeping offensive on June 9, IS and allied Sunni groups have conquered the country's second city of Mosul, overrun large swathes of five provinces and declared a "caliphate" straddling Iraq and Syria.
The onslaught has fanned the flames of sectarian tension between Iraq's Shiite majority and sunni minority that had already claimed thousands of lives this year alone.
Prime Minister Nuri al-Maliki's alliance comfortably won elections in April but he has faced mounting domestic and foreign pressure to step aside since the flare-up.
The Shiite premier has accused the Sunni mainstream of condoning the Islamic State's offensive and "dancing in the blood" of the jihadist onslaught's victims.
But many retort it was Maliki's own brand of sectarian politics that brought the country to the brink of collapse.
In his talks with Maliki, Ban Ki-moon was expected to highlight the plight of the 600,000 Iraqis displaced over the past few weeks and encourage the country's fractious politicians to speed up the government formation process.
For weeks, bickering factions appeared to turn a deaf ear to repeated pleas from the UN and the powerful Shiite clergy to iron out their differences and agree on a consensus government.
Earlier on Thursday, in a late-night meeting held behind closed doors, the main Kurdish parties agreed on a common candidate for the post of president.
"Fuad Masum is the only candidate of the Kurdish blocs for the position of president," a senior Kurdish official who witnessed the vote told AFP.
An unofficial power-sharing deal reached in the aftermath of the 2003 US-led invasion reserves the post for a Kurd, meaning Masum is almost guaranteed to become the next head of state.
A parliament session scheduled for later Thursday could confirm Masum as president, a move that would pave the way for a deal on the much more powerful post of prime minister.
Iraqi lawmakers' failure to vote on Thursday could delay the process by at least a week due to the upcoming Eid al-Fitr holiday marking the end of the Muslim fasting month of Ramadan.
The Taji attack and fears of a campaign of suicide car bombs in Baghdad and elsewhere during the feast set a tense backdrop for Ban Ki-moon's visit.
In 2007, on one of his first foreign trips as UN secretary general, he famously ducked behind the podium when an explosion rocked the Green Zone where he was giving a press conference with Maliki.
Despite the billions of dollars spent on training and equipment by the United States during its eight-year occupation, Iraq's million-strong army completely folded when insurgents attacked last month.
Maliki has called on the US for help, but Washington is reluctant to boost military aid while the country's political leadership remains divided.
He is instead increasingly turning to Russia, where Defence Minister Saadun al-Dulaimi was meeting officials to seek "weapons, equipment and modern military aircraft."