Libya's army has clamped down on militias and other armed groups, including hard-line Islamists, that still control large areas of the country more than a year after Muammar Gaddafi's fall.

Late on Friday Ansar al Sharia, a militia linked with the attack on the US consulate in which ambassador Christopher Stevens and three other Americans died, was swept from its bases in Benghazi by mass demonstrations of angry residents.

On Saturday Ansar al Sharia and another Islamist militia, Abu Slim, withdrew from their five bases in Derna in eastern Libya, an Islamist stronghold. They said they were disbanding.

Yesterday the army gave all armed groups 48 hours to evacuate military compounds, state property and property of former regime members in Tripoli and surrounding areas.

The army ordered "all individuals and armed groups occupying military compounds, public buildings or property belonging to members of the former regime to evacuate these sites within 48 hours", threatening to use force if the groups did not comply

Yesterday the army dislodged a militia from a military complex on the road leading to Tripoli's main airport. The soldiers arrested its members and seized its weapons.

Friday's invasion of Ansar al Sharia's compounds, which met little resistance, appeared to be part of a sweep of militia bases by police, troops and activists. But in a sign of Libya's fragility, after tackling Ansar al Sharia's bases the crowd went on to attack a pro-government militia, mistaking them for Islamists, triggering an armed response in which 11 people died.

Libya's new rulers have struggled to impose their authority on the many groups that are still armed, and in fact rely on some to provide security.

The interim Libyan leader, Mohammed Magarief, promised to disband illegal militias following the death of Mr Stevens.

All camps and militias not under the authority of the government would be dissolved and unauthorised checkpoints would be banned, he said, adding: "We call on everyone to stop using violence and carrying weapons in the streets and squares and public places."

Ansar al Sharia denies attacking the US consulate

Siraj Shennib, a 29-year-old linguistics professor who had protested against militias in Derna, said: "The militia saw what happened last night and they decided: we will not kill our brothers. So they disbanded."

Shennib said protesters had maintained a vigil against the groups in Derna for 10 days.

Residents blame the militia for creating a climate of insecurity.

"The people started coming because it has reached the limit. They are saying: we've had enough," he added.

Libya's government had promised Washington it would find the perpetrators of the attack on the consulate.

The attack and the outrage across the Muslim world at the US over an American-made anti-Islam video raised questions about President Barack Obama's handling of the Arab Spring.

The latest events appeared at least in part to vindicate Mr Obama's faith in Libya's nascent democracy.