Two Libyan protesters were killed and dozens wounded early Saturday as hundreds of demonstrators attacked militia compounds in a surge of anger at armed groups in Benghazi whose unchecked powers led to last week's killing of the U.S. ambassador.

For many Libyans, the Sept. 11 attack on the U.S. Consulate in Benghazi was the last straw in one of the biggest problems Libya has faced since last year's ouster and death of longtime dictator Muammar Qaddafi: the multiple mini-armies armed with machine guns and rocket-propelled grenades that are stronger than government security forces.

But in an indication of government fears of a sudden security vacuum without the militias it relies on to keep order, officials called on protesters to respect "legitimate" militias.

While the late Friday protests were planned in advance though social networking sites and flyers, the storming of the heavily armed militia headquarters took many by surprise. After breaking off from a huge anti-militia march -- the biggest in the eastern city since the fall of Qaddafi's regime last October -- protesters overtook a building used by Islamist militia Ansar al-Sharia, set fire to a vehicle and offices after freeing three detainees held in an underground cell. The group is linked to the killing of U.S. Amb. Chris Stevens.

Protesters on foot and in cars, some carrying guns and others machetes, moved to another heavy armed compound on Benghazi's outskirts that houses Rafallah Sahati militia.

Panicked, Libyan government officials urged protesters to differentiate between what it called "legitimate and non-legitimate" militias.

The militias, a legacy of the rag-tag popular forces that fought Qaddafi's regime, tout themselves as protectors of Libya's revolution, providing security where police cannot. But they now face public criticism and are accused of acting like gangs, detaining and intimidating rivals and carrying out killings.

Libyan military chief of staff Youssef al-Mangoush said three big militias -- Rafallah Sahati, Feb. 17 and Libya Shield -- are considered "pro-government" and warned protesters against pushing for what he described as "counter-revolution" goals. The government heavily depended on Rafallah Sahati, for example, to secure Benghazi during the country's first national elections in July in decades. The militia took its name from an Islamist fighter who battled fiercely against Qaddafi's forces earlier in the revolution.

But most of Libya's militias still answer to their commanders before the state. Protesters, like those on Friday, want the fighters to be trained outside Benghazi and follow state army orders as individual soldiers and not as part of a militia. Many of the militiamen are unruly and undisciplined civilians who raised arms during the eight-month war.

Mohammed al-Megarif, head of Libya's General National Congress, ordered protesters to leave alone militias that are "under state legitimacy, and go home." Nearly seven hours of clashes ended shortly after his demand that was broadcast on local Libyan TV channels.

Standing next to charred cars and several pickup trucks mounted with anti-aircraft guns, weary armed militiamen guarded the entrance of the Rafallah Sahati compound. The compound was once one of Qaddafi's houses. Some of the men wore military uniforms, while others were dressed in Afghani-style clothes.

"Those you call protesters are looters and thieves," said Nour Eddin al-Haddad, a young armed man with hanging a rifle on his back. "We fought for the revolution. We are the real revolutionaries. We are part of the army. I have official documents to prove it."

However, 22-year-old protester Farag Akwash, who was wounded with a bullet in his arm, described it as "a Moammar militia."

"If you are really an army force, you wouldn't shoot at the people. You wouldn't kill people. You protect people," said Akwash whose arm was hidden under a bandage Benghazi Medical Center. "We don't want to see militias in the city anymore. We only want to see army and police."

Mohammed al-Fakhri, manager of al-Hawari hospital in Benghazi, said two young men died and about 30 were injured in the clashes.

Some media reports put the number of dead to four, but it was not immediately possible to confirm that.