As fires blazed and protesters danced in the ruined compound of a vanquished jihadist militia, I watched as the citizens of the Libyan city of Benghazi staged a dramatic display of raw people power.Numbed by the murder of an American ambassador in their city, furious with jihadist militias lording it over them and frustrated by a government too chaotic and intimidated to react, ordinary Benghazians took matters into their own hands.

Elsewhere in the world jihadists staged fiery attacks on foreign targets. In Libya they were sent running by people power. A rally called to Rescue Benghazi on Friday night became the launch pad for a spontaneous retaking of the streets, and more – a retaking of the soul that saw this city become the cradle of last year's Arab spring revolution.

Ansar al-Sharia militia, blamed by many for the killing of ambassador Chris Stevens and three of his diplomats had last week deployed anti-aircraft guns around their Benghazi compound, fearing attack from drones and US warships. But the attack, when it came, was from a very different direction. Civilian. Unarmed. And with nothing more than the desperation of a population staring anarchy in the face.

For the people of Benghazi, the killing of Stevens was the final outrage in a campaign of extremist violence that had seen other consulates firebombed, the convoy of Britain's ambassador rocketed, commonwealth war graves vandalised and 14 officials assassinated. As foreign missions fled and businessmen cleared out, Benghazi found itself cast as Libya's Dodge City. And in the absence of a sheriff to impose order, its people staged their own spontaneous cleansing.

The rally on Friday was peaceful: crowds of men, women and children marched on central Benghazi, with balloons, flags and placards, many calling for justice for the killers of Stevens. "We are Islam, we are not extremists!" they chanted.

Ever since the 11 September attack on the US compound that left Stevens and three fellow diplomats dead, Benghazians have been incredulous at the inability of government to act. No serious investigation has been launched to catch his killers, the government cowed by the power of jihadist militias.

But support for the protest was everywhere. The defence minister refused to give his backing, but air force pilots made their feelings known: an attack helicopter circled Friday's protest to protect it and a pilot made low thundering passes over the crowd to remind them of the revolutionary slogan: "The army is with the people."

When night fell, the dam broke. The women and children of the rally were escorted home and the crowd surged towards militia bases. First to go was the Abu Salem Shahouda militia base, behind the seafront Tibesti hotel, and blamed by locals for thuggery and intimidation. A crowd of hundreds of young men, some teenagers, smashed through the gates and into the compound.

I was propelled in with them, as the frightened militiamen were manhandled out of the gates. Minutes later three jeeps loaded with red-capped military police screeched into the compound, weapons ready, unsure what they would find. The protesters embraced them. "It's like in the revolution," said colonel Ben Eisa, taking command of the abandoned Abu Salem Shahouda base. "We are taking orders from the people." It was as easy as that. Months of militia violence ended by a show of unarmed force.

Then came Ansar al-Sharia: a 300-strong force blamed by Libya's head of state Muhammad Magariaf for involvement in Stevens's death. As the demonstrators approached, the militiamen flooded out of their compound and loosed volleys of machine gun fire into the air. The crowd, bursting with the frustration of months of humiliation, simply kept coming. The militia, who had vowed to fight American air power, fled before people power.

Compound buildings were torched, cars set ablaze and looting of everything not nailed down began as, belatedly, red-capped military police arrived. "We are in control of this place," said colonel Saleh Yemeni, sporting a red beret and the silver wings of the parachute regiment, as a flaming car burned behind him. "We are with the people."

A well-built man, Ehad El Farsi, stopped me to ask if I was American and to apologise on behalf of Benghazi for the killing of Stevens. Told I was English, he explained he was a politics professor at Benghazi university and wanted to talk to me some time about the merits of singer Chris Rea. "What you have here is the people taking action," he said. "All the people."

TV pictures may give the impression of mob rule. Being there felt it felt more like a cup final crowd toasting victory. Then the cry went up to march on Hwari, the sprawling base of another militia, Raffala al-Sahati, to which Ansar al-Sharia men were believed to have fled. El Farsi found his car, a BMW, and roared off south.

Protesters crammed into cars, hooting horns and waving Libyan tricolours as an impromptu convoy surged south. But this time the response was different. The first protesters who marched on the gates were met by machine gun fire, triggering pandemonium. Cars bringing more protesters ran into the traffic jam of abandoned vehicles and civilian cars trying to ferry the wounded to hospital. Pickup trucks with anti-aircraft guns manned by military police sat, their crews unsure if they should return fire.

Amid a cacophony of car horns, shouts and the rattle of machine gun fire, red tracer slashed the night sky and protesters dashed for cover. "The were shooting at the people – the crowd were all running away," said Muhammad el-Gadari, an aviation student who had gone there to search for his younger cousin.

I had abandonded my vehicle to try to get to the battle by foot through the chaos of traffic and angry protesters, when a huge, bearded man in a white robe grabbed me, yelling in my ear and violently pushing me backwards. He spoke no English, and I was separated from my translator. When he caught up with us, the man in the robe explained he was not attacking me but defending me: "You must go away, it is not safe," he said. "We have to protect our foreigners."

As protester numbers grew and fire was returned, the base garrison fled, abandoning vehicles, guns and huge quantities of ammunition which the crowd looted. City hospitals were meanwhile forced to deal with carnage not seen since last year's war: surgeons were summoned from their beds, blood donors requested. By dawn the toll stood at 11 dead and 19 injured.

The wounded included Abu Baker Feraz, who had his leg smashed by a panicking militiaman escaping in a jeep. "It was an Ansar al-Sharia guy. I know his face. I have seven brothers – we want to find this man." As he was wheeled away to be operated on at Benghazi medical centre, his hand snaked out from the blue shawl that covered him. "I want to say something," he said. "Ansar al-Sharia, they have somebody from Afghanistan, somebody from Tunisia, somebody from Libya. Islam is not in Ansar al-Sharia."

It is a refrain you hear across Benghazi: Libya is a conservative Muslim country, and perhaps for this reason jihadists are distrusted for wanting to tell Libyans how to interpret their faith. Cynics say jihadists were wrongfooted by the revolution, won by the ordinary people and Nato, then by July elections that were won by a pro-business coalition, and are staking all on taking power – and Libya's oil wealth – by force.

The desperate hope here is that the outside world that gave Libya such support in its revolution does not turn away. "How can you have business if you can't guarantee security?" said Hana el-Galal, a prominent civil rights activist in the city. "Everybody now is rallying against organised extremism."

For now, the city is calm. Whether it stays that way is anyone's guess: the political vacuum at the heart of Libya's government remains, and the Islamists have powerful political allies.

Some in Benghazi worry that the streets are now protected by the same police and army commanders who made their careers in Muammar Gaddafi's security forces. Ansar al-Sharia is still around, somewhere, but its leaders are perhaps mindful that, as was shown last year against the Gaddafi regime, Libyan people power should not be underestimated.