At least 32 people were killed and almost 400 wounded in gun battles between Libyan militiamen and armed residents in Tripoli on Friday in the worst street fighting for months to test the shaky central government.
Prime Minister Ali Zeidan is struggling to control rival militias, Islamist militants and other former fighters who refuse to surrender their arms two years after helping to overthrow Moammar Gaddafi in a NATO-backed revolt.
After Friday's violence, Zeidan demanded that all militias "without exception" leave Tripoli, but the clashes underscored how little his fledging military can do to curb ex-rebels, who have also shut down Libya's oil exports for months.
Friday's bloodshed, the worst in Tripoli for many months, began when militiamen from the city of Misrata fired at about 500 protesters demanding their eviction from the capital after they had fought rivals for control of city districts.
A Reuters reporter saw an anti-aircraft cannon firing from the "Gharghur brigades" gated compound into the crowd as protesters chanted: "We don't want armed militias!"
Demonstrators fled but then returned, heavily armed, to attack the compound, where the militiamen remained holed up past nightfall as fighting continued.
Dozens of soldiers in trucks tried to separate the sides, and sealed off roads to stop more people joining the clashes.
Heavy smoke could be seen rising from the scene in the Gharghur district, where many of Gaddafi's closest collaborators used to live before the uprising.
At least 32 people were killed and 391 wounded, a Health Ministry official told Reuters.
Zeidan denounced the killing of protesters. "The demonstration was peaceful and had been permitted by the Interior Ministry, and then the protesters were fired on when they entered the Gharghur district," he said.
"Armed groups must leave"
"The exit of armed groups from Tripoli is not something up for debate but necessary and urgently needed," he told Reuters TV and the Libya Ahrar channel in an interview.
He did not elaborate.
Libya's turmoil and the weakness of its border controls are worrying its North African neighbours. France this week said it was considering offering more counter-terrorism training and aid to help Libya prevent militancy spilling over its frontiers.
The French intervention in neighbouring Mali this year drove some Islamist militants with links to al Qaeda across the border into Libya's lawless southern deserts, where the central government has little or no say.
So far, the capital has been spared the almost daily bombings and killings that plague Libya's second city, Benghazi, in the east. But when clashes between rival militias do break out, the nascent armed forces are no match for them.
The Misrata gunmen had fought twice last week with a rival group that had detained one of their members for driving a car without number plates.
On Friday, air force planes circled overhead during the clashes. "We want to make sure the militia don't bring in any reinforcements," said army spokesman Ali al-Sheikhi.
Strikes and armed protests around the country by militia and tribal gunmen demanding payments or more autonomy rights have also shut much of the OPEC member's oil output, depriving the government of its main source of income.
The authorities have tried to defuse the threat of the militias by placing them on the government payroll and assigning them to provide security.
But the gunmen often remain loyal mostly to their own commanders and fight for control of local areas, especially their weapons or drug smuggling rackets, or to settle personal feuds.
Zeidan was himself briefly abducted in October by a militia group on the government payroll.