The militia suspected of killing the US ambassador to Libya nearly two weeks ago has been driven out of its base in the eastern city of Benghazi.Police and protesters stormed the HQ of the Islamist group Ansar al-Sharia.
The HQ of the Sahaty Brigade, said to have official backing, was also stormed. At least nine people were killed there, another died elsewhere.
The attack on the US consulate was triggered by an amateur video made in the US which mocks Islam.
Protests against the film have been held across the Muslim world. At least 19 people died in Pakistan on Friday alone, in clashes with police trying to stop protesters attacking US diplomatic buildings.
US citizens have been urged not to travel to Pakistan and the US embassy has paid for adverts on Pakistani TV showing President Barack Obama and Secretary of State Hillary Clinton condemning the film.
Witnesses say supporters of Ansar al-Sharia gathered outside its Benghazi headquarters, in front of the crowd, waving black and white banners.
They fired into the air to try to disperse the protesters, but fled with their weapons after the base was surrounded by waves of people shouting "No to militias".
Buildings and a car were set alight and fighters evicted.
In a statement later, a spokesman for the group said militiamen had evacuated the premises after their commander had ordered to "hand them over to the people of Benghazi" to preserve security.
However, in a standoff outside the headquarters of the Sahaty Brigade in the city, three people were killed and at least 20 injured according to witnesses and officials.
The two sides are said to have exchanged rocket and light arms fire for two hours before the brigade decided to move out.
Protesters then set fire to one of the main buildings and pillaged a weapons depot, a journalist for AFP news agency at the scene reported.
Another person was killed and another 20 injured in other incidents, city hospitals said.
On Saturday, sources said the bodies of six people had been found. They had been shot "execution-style".
The BBC's Rana Jawad in the capital Tripoli says the Sahaty Brigade is believed to be operating under the authority of the ministry of defence.
Senior Libyan officials say that while they welcomed the protests, people should differentiate between the rogue militias and honest rebel brigades that helped to secure the town in last year's uprising against Col Muammar Gaddafi.
Earlier, some 30,000 protesters marched through Benghazi calling for an end to the armed groups and a return to the rule of law.
There has been a wave of hostility towards the militias since US Ambassador Christopher Stevens and three others Americans died in last week's attack on the Benghazi consulate.
"I don't want to see armed men wearing Afghani-style clothes stopping me in the street to give me orders, I only want to see people in uniform," said university student Omar Mohammed, who took part in the takeover of the Ansar al-Sharia compound.
Many Libyans have expressed outrage at the attack on the US consulate. Ansar al-Sharia denies being behind it.
Libya's interim government has since come under renewed and intense pressure to rein in well-armed extremist militia groups and force them to disband.
Friday's march was the largest seen in Benghazi - considered the heartland of Libya's uprising - since Col Gaddafi was deposed.
Armed militia groups which helped to defeat Gaddafi remain powerful in many parts of the country.
They are better armed and more numerous than Libya's official army, and there have been reports of militias intimidating and carrying out killings against rivals.