By QASSIM ABDUL-ZAHRA and SINAN SALAHEDDIN
BAGHDAD (AP) -- Kurdish politician Fouad Massoum was named Iraq's new president on Thursday hours after an attack on a prison convoy killed dozens of people, brutally underscoring the challenges faced by the country's leaders as they struggle to form a new government.
Massoum, 76, one of the founders of the Patriotic Union of Kurdistan party led by the previous president, Jalal Talabani, accepted the position after winning two-thirds of the votes, noting the "huge security, political and economic tasks" facing the government.
Last month's rapid advance of the Islamic State extremist group, which captured Iraq's second largest city of Mosul, has plunged the country into its worst crisis since the withdrawal of U.S. troops in 2011 and inflamed already-existing tensions between sectarian and political rivals.
Hours before Massoum was elected, militants fired mortar shells at army bases where detainees facing terrorism charges were being held in Taji, some 20 kilometers (12 miles) north of the capital. Fearing a jailbreak, authorities evacuated the facilities, officials said.
But as the prisoners were being bussed through a remote area nearby militants attacked again, this time with roadside bombs, igniting a gunbattle that left 52 prisoners and eight soldiers dead, the officials said, adding that another eight soldiers and seven prisoners were wounded.
It was not immediately clear if the prisoners were killed by soldiers or militants, or if the Islamic State group was involved.
Islamic State militants have staged several jailbreaks, including a complex, military-style assault on two Baghdad-area prisons in July 2013 that freed more than 500 inmates.
The vote for president -- a largely ceremonial post previously held by ailing Kurdish leader Talabani - is widely viewed as a step toward achieving consensus among political rivals, seen as necessary for tackling the deteriorating security crisis.
Massoum is considered a soft-spoken moderate, known for keeping good relations with Sunni and Shiite Arab politicians.
He was born in what is now the Kurdish regional capital of Irbil in 1938. He entered politics when he was 16 years old, taking part in Kurdish-organized demonstrations. He joined the Kurdistan Democratic Party in 1964.
From 1973 to 1975 he was the Cairo representative of Kurdish rebels battling the Arab-dominated government in Baghdad, then went on to establish the Patriotic Union of Kurdistan with six Kurdish politicians, including Talabani.
The next step in Iraq's political transition will be for Massoum, who has already officially assumed the title of president, to select a candidate for prime minister to try to form a new government.
Prime Minister Nouri al-Maliki's bloc won the most seats in April elections, but he has faced mounting pressure to step aside, with critics accusing him of monopolizing power and alienating the country's Sunni and Kurdish minorities, contributing to the latest unrest.
Al-Maliki has however vowed to remain in the post he has held since 2006.
U.N. chief Ban Ki-moon arrived in Baghdad earlier Thursday, urging lawmakers to "find a common ground" so they can address the crisis sparked by the rapid advance of the Islamic State extremist group and allied Sunni militants across much of northern and western Iraq last month.
At a press conference with al-Maliki, Ban said Iraq is facing an "existential threat," but one that could be overcome if it forms a "thoroughly inclusive government."
Under an unofficial agreement dating back to the 2003 U.S.-led invasion, the presidency is held by a Kurd while the prime minister is Shiite and the parliament speaker is Sunni.
Speaking alongside the U.N. secretary-general, al-Maliki said he is committed to quickly forming a government.
"Despite the fact that we have problems...we are moving at a confident pace to implement the mechanisms of the democratic work," al-Maliki said.
More than a million Iraqis have been displaced this year, many of them fleeing the latest wave of violence, according to the U.N.
Ban strongly condemned the persecution of religious and ethnic minority groups by jihadi militants in Mosul and elsewhere in Iraq, and offered continued U.N. support to the refugees fleeing the violence.