Rival Libyan militias surrendered their bases to the army and retreated from Tripoli on Thursday in the face of popular anger against their refusal to disarm in the two years since they toppled longtime leader Moammar Gadhafi.
Islamist militants have become an increasing worry for Western powers, concerned that violence in the OPEC country could spill over to its North African neighbors.
At Mittiga airbase, militias tied to the Islamist-leaning Supreme Security Committee (SSC) said they would turn over control to the army. The powerful al Qaqaa brigades from Zintan, southwest of Tripoli, also handed over their base, commanders and officials said.
"In response to the people's demands, we decided to hand over our headquarters, and all weapons inside," said a spokesman for the deterrence force, one of the SSC militias. "We will sign up for the police as individuals."
Prime Minister Ali Zeidan told the ceremony in Mittiga: "Clearing Tripoli of armed presences is a decision that will include all armed brigades without exception."
But with Libya's fledgling military still outgunned by the former fighters, his government may struggle to reassert control over the gunmen. Zeidan himself was briefly abducted by militia last month.
"The government is still weak and doesn't have enough force to secure the city or the country," said Adel Faraz, a public employee in Tripoli. "This might be a good initiative, but I don't trust them not to come back or to give up their weapons."
Militias also pose a challenge outside Tripoli. For months, former fighters once employed to guard oil sites have taken over ports in the east, disrupting exports in protests for regional autonomy. The International Monetary Fund expects the economy to shrink by 5.1 percent this year.
Libyans have grown increasingly frustrated with the gangs of ex-fighters who remain loyal to their commanders in turf wars and disputes, even after the government put them on its payroll to provide security in Tripoli.
Many of the militias, who have heavy weaponry and trucks with anti-aircraft cannons, were associated with the defense or interior ministries as vigilantes or security guards.
The retreat from the capital was triggered by clashes last Friday, when more than 45 people were killed after gunmen from one militia opened fire on protesters marching on their base to demand they leave the city. It leaves Tripoli's security mostly in the hands of the nascent armed forces and police.
Militias from Misrata, including the Gharghour Brigades which were involved in the clashes, withdrew from Tripoli on Monday under instructions from leaders of their city, which lies east of the capital.
The U.S. military and NATO have promised aid and training to build up Libya's forces. But most programs are just starting and militias are unlikely to disband or disarm while their rivalries over territory and control go unresolved.
Those tensions mirror divisions in Libya's government, where the secular National Forces Alliance has been in a standoff with a wing of the Islamist Muslim Brotherhood over the country's transition to democracy since Gaddafi's fall.
Libya is still trying to write a new constitution to address the distribution of oil wealth and regional powers. Analysts say militia rivalries are likely to continue until the country makes progress toward new elections.