An Islamist militia has been driven out of Benghazi by cheering crowds in a surge of protest against the armed groups that control large parts of Libya.

A spokesman for the ousted group, Ansar al Sharia, claimed they had evacuated their bases "to preserve security in the city".

Hundreds of protesters angry over last week's killing of the US ambassador stormed the compounds of the Islamic extremist militias suspected of carrying out the attack.

But the crowd went on to attack a pro-government militia, believing them to be Islamists, triggering an armed response in which at least 11 people were killed and more than 60 wounded.

The invasion of its compound, which met little resistance, appeared to be part of a coordinated sweep of militia bases by police, government troops and activists following a 30,000-strong demonstration against militia units in Benghazi on Friday.

Demonstrators pulled down militia flags and set a vehicle on fire inside what was once the base of Libyan leader Colonel Muammar Gaddafi's security forces.

Hundreds of men waving swords and even a meat cleaver chanting "Libya, Libya", "No more al Qaeda!" and "The blood we shed for freedom shall not go in vain!"

One of the demonstrators Hassan Ahmed said: "After what happened at the American consulate, the people of Benghazi had enough of the extremists.

"They did not give allegiance to the army. So the people broke in and they fled."

Other signs mourned the killing of the ambassador, reading: "The ambassador was Libya's friend" and "Libya lost a friend."

Libya has struggled to control the heavily-armed militias which sprang up to overthrow Colonel Gaddafi's regime.

A new wave of hostility towards them was sparked when US Ambassador Chris Stevens and three other Americans died in the September 11 attack on the Benghazi embassy.

Many Libyans have expressed outrage at the attack on the US consulate, which followed a protest triggered by an anti-Islam film made in America.

US Secretary of State Hillary Clinton said on Friday that the killings were a "terrorist attack", and White House spokesman Jay Carney said those responsible may have links to al Qaeda.

While Libya's militia groups claim they are protectors of the nation's revolution, some say they act like gangs, detaining and intimidating rivals and carrying out killings.

"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 Omar Mohammed, a university student who took part in the protests.

Activists and residents have also held a sit-in for the past eight days outside the Sahaba Mosque in the city of Darna.

"The killing of the ambassador blew up the situation. It was disastrous," said Ayoub al Shedwi, a young Muslim preacher in Darna. "We felt that the revolution is going in vain."