The Libyan authorities have given armed groups two days to vacate military bases and compounds as they seek to capitalise on the wave of people power that drove an Islamist militia from Benghazi at the weekend.

Jihadist militias in Derna, Libya's Islamist stronghold, threw in the towel on Sunday, withdrawing from their stronghold and announcing they were disbanding to avoid a repeat of the scenes in Benghazi in which angry crowds sent armed gunmen fleeing. One of the routed militias was blamed for an attack on the US consulate two weeks ago that left four Americans dead including the ambassador, Chris Stevens.

The de facto head of state, Muhammad Magariaf, president of Libya's parliament, met Benghazi politicians and security officials, anxious to fill a security vacuum that has emerged from the weekend violence, in which at least 11 people died.

"The army chief Yussef al-Mangoush and Muhammad Magariaf have ordered all illegitimate militias should be removed from compounds and hand over their weapons to the national army," said Adel Othman al-Barasi, a spokesman for the defence ministry, according to Reuters. "A committee made up by the military police has been formed to take over the compounds and the weapons and hand these over to the army."

Benghazi's army garrison commander, General Hamad Belkhair, said he was moving military police units into vacated militia bases. "What happened was a big mess," he said of the takeover by protesters of Benghazi's three militia bases on Friday night and Saturday morning. "But it has left the government clearly in control of the streets."

Bilal Bettamer, a 22-year-old law student in the city who was one of the organisers of the Benghazi protests, said he was optimistic the militias would be disbanded. "You can't have 100% success in these situations. [But] that's what we wanted – the militias are put on notice and everyone knows now that this country will refuse any extremists and will eventually get rid of them, and become a country that we wanted on 17 February."

He condemned the apparent killing of militia guards as a "stupid move" and speculated that pro-Gaddafi elements could be to blame. He even praised the courage of the militias for disbanding, claiming it showed they respected democracy.

"Militias are not evil people, they are good people and they have saved Libya before. But it is time for legitimacy to take its place for the police and army. You can't build a country based on militias.

"The army are back on the streets. You can see the army and police at night. The collection of individual weapons is beginning right now. They are doing their expected job. They have put small militia on notice to evacuate the neighbourhood. The army got braver. Everyone is telling them, strike with an iron fist."

Yet extremists remain a presence: Belkhair himself was kidnapped on Saturday morning by masked gunmen and held for six hours before being released unharmed. He said he thought the group, who did not identify themselves, wanted him to limit the army's role in securing the city. Belkhair and police commanders are uneasily aware that the surge of people power that has swept militias from the streets could degenerate into anarchy, and that he lacks the manpower to impose order.

An army unit from Sirte, former stronghold of the late dictator, Muammar Gaddafi, has occupied the compound of the Raffala al-Sahati militia, whose soldiers shot many of the 11 killed in the early hours of Saturday. Investigators are trying to establish who killed six militiamen whose bodies were found, each with a bullet to the head, in a field near the Raffala base.

In Derna, a centre for Islamist resistance against the Gaddafi regime, two powerful jihadist formations, Abu Salem and Ansar al-Sharia, have agreed to disband. Commanders of both formations – the latter linked to the group blamed for the killing of Stevens – told Libya's state news agency that they had decided their role was over.

In Tripoli, many foreign embassies remain in security lockdown, fearing jihadist units in the capital will seek revenge for the humiliating rout of their comrades in eastern Libya.

Benghazi officials say the way is now clear for Washington to deploy an FBI team that is kicking its heels in Tripoli to join the investigation into the death of Stevens, who died from smoke inhalation after the attack on the consulate compound.