Officials said that al-Jaafari had won 64 votes on Sunday, narrowly defeating Adel Abdul Mahdi, the vice-president, who got 63 in a ballot after the group failed to reach an agreement by consensus on Saturday.
According to the Iraqi constitution, the new president will formally designate the choice of the biggest bloc in parliament after the assembly convenes.
Shia lawyers cast their votes at the heavily guarded home of Abdul-Aziz al-Hakim, the head of Abdul Mahdi's party.
The contest for prime minister became a two-horse race after Nadim Jabiri of the Fadhila Party and Hussein Shahristani from an independent Shia bloc decided to withdraw.
Al-Jaafari, a doctor, is a member of the Dawa Party and spent years in exile in
His government, which took office in April, had been widely criticised for failing to improve the country's crumbling infrastructure or deal effectively with security.
The alliance of Shia religious parties took the biggest number of seats in the vote on 15 December.
The United Iraqi Alliance was confirmed on Friday as the winner of the election in December, paving the way for the formation of the first permanent post-Saddam government.
It won 128 seats in the 275-member parliament, while an alliance of Sunni and secular groups, the Joint Council for National Action, took 80, and the Kurdish Alliance won 53.
The remaining seats are shared by small parties, mostly representing ethnic and religious minorities.
Relentless violence
Meanwhile, there was no let-up in violence as bomb blasts and gun attacks killed at least five people and wounded at least 38 in
Two Iraqi police officers were killed and another nine wounded when unidentified gunmen attacked a police convoy near Amiriyat al-Falluja in the city of
Iraqi police sources said seven police officers were wounded when two explosive devices targeting their patrol blew up in
In central
In al-Aazamiya, police sources said a booby-trapped bicycle blew up near a
The
PHOTO CAPTION
From left to right: Iraqi Prime Minister Ibrahim al-Jaafari, Iraq's National Security Advisor Muafq al-Rubaye, Abdel Aziz al-Hakim, chief of the conservative Shiite United Iraqi Alliance and Vice President Adel Abdel Mehdi attend a press conference, Sunday in Baghdad. (AP)