Members of Libya's 200-strong national assembly on Wednesday elected technocrat Mustafa Abu Shagur as the country's new prime minister in a close vote.
Shagur, previously deputy prime minister, won 96 votes, beating the liberal candidate Mahmud Jibril by just two votes to take control of Libya's transitional administration for the next 18 months.
Shagur is considered close to Islamist groups and won after two rounds of voting thanks to the support of deputies from the Justice and Construction Party, which sprang out of Libya's Muslim Brotherhood.
Signup to our newsletter and follow us on Facebook and Twitter!
They backed him in the second round after their preferred candidate was eliminated in the first. Their party is the second strongest group in the assembly, with 17 seats.
Shagur, who takes over from Abdel Rahim al-Kib, faces the daunting task of restoring security in the troubled country.
He was elected in the wake of Tuesday night's attack on the US consulate in Benghazi, which killed Washington's envoy to Libya and three colleagues, and wounded at least five other US nationals.