Libya's national congress elected a human rights lawyer as interim prime minister on Sunday, a week after his predecessor was sacked for failing to present a cabinet lineup that political factions could agree on.

Ali Zidan, a former independent congressman, won 93 votes, securing a majority of those who voted in a poll to determine the country's leader for a transitional period of around 20 months.

Zidan's top priority will be to name a new government that congress approves. The cabinet will be faced with the task of disarming thousands of young men who fought in last year's eight-month civil war that led to the capture and killing of dictator Muammar Gaddafi.

The ministers will be pressed to provide basic services, restore security by creating a military and police force capable of asserting authority over disparate militias left over from the war and unify the country's tribes and towns.

One such militia, a radical Islamist group that now claims to have dissolved, has been linked to the attack last month on the US consulate in Benghazi during which the American ambassador and three others were killed.

Militias are currently deployed on the outskirts of the mountain town of Bani Walid, one of the few remaining strongholds of Gaddafi loyalists. The possibility of an outbreak of violence there highlights the highly polarised atmosphere.

Any prime minister who wants to impose his authority on the militias will need broad national support for his government, but such support is hard to obtain.

The 200-member congress selected Zidan following the dismissal last week of Mustafa Abushagur after just 25 days in the post for failing to present a cabinet list that satisfied legislators.

Some parliamentarians argued Abushagur's cabinet choices were not diverse enough, involved too many unknown individuals for key posts and was formed of too many figures from the previous interim government, which was seen by some Libyans as weak and corrupt.

Zidan was a diplomat under Gaddafi before defecting in the 1980s and joining Libya's oldest opposition movement, the National Front for the Salvation of Libya.

On Sunday, he edged out local government minister Mohammed al-Harari by eight votes. Harari appeared to be the Islamists' choice for prime minister.

Zidan, born in 1950, holds a master's degree in international relations. He had previously run as a candidate for Libya's interim presidency, but lost a vote in congress against former opposition leader Mohammed el-Megarif.

The two biggest blocs in parliament, the National Forces Alliance, led by former prime minister Mahmoud Jibril, and the Muslim Brotherhood's political arm, the Justice and Construction party, held meetings last week to try to agree on a candidate after Abushagur's dismissal.

Zidan had been Jibril's preferred candidate against El-Megarif for the post of president when he lost.

Saleh Gawdet, an independent congressman, said the elected body had been searching for "a nationalist who does not belong to any party, but who served the country during the revolution".