Demonstrators cheer after storming the headquarters of the Islamist Ansar al-Sharia militia group in Benghazi on Friday. (ASMAA WAGUIH/REUTERS)

Thousands of Libyans marched through Benghazi on Friday to demand the dismantlement of the hundreds of armed militias that have ruled the country’s streets since a revolution ended the 42-year rule of Moammar Gaddafi.

By early Saturday, two protesters were killed and dozens wounded, according to the Associated Press. Protests took place at militia bases, including the headquarters of the Islamist militia Ansar al-Sharia, which some blamed for last week’s attack on the U.S. Consulate.

The Sept. 11 attack, which left the U.S. ambassador and three other Americans dead, has prompted anger and soul-searching among many of Benghazi’s residents, who believe that religious extremists operating in an atmosphere of weak central governance were behind the assault.

But the government in Tripoli has struggled to deal with the militias, which are composed largely of the young men who fought in last year’s revolution. The government’s efforts to bring some of the militias under a more unified national force have failed to deliver state-run security to Libya’s streets.

As protesters draped in the red, black and green of the Libyan flag carried signs reading “Benghazi deserves better” and “No legitimacy, except to the police or the army,” Ansar al-Sharia held its own protest in nearby Al-Kish Square. The militia’s members gathered to call for the implementation of Islamic law in a demonstration that the anti-militia crowd said marked a provocation.

The dueling protests underscored a broader struggle underway in the country, nearly a year after Libyans from across the political spectrum joined hands in an eight-month war to oust Gaddafi. It is a battle to define a new Libya — to answer the crucial question of what the Libyan people, government and culture look like when the shackles of dictatorship are thrown off.

“I think the struggle that’s eating people up right now is the struggle for an identity,” said Alya Barghathy, an English professor at Benghazi University who joined the anti-militia protest Friday. “After all these years of being neglected and living in darkness, they don’t know who they are.”

The collapse of Gaddafi’s regime left a system in a shambles. After decades of repression, the country has lurched forward in recent months to form political parties and elect a General National Congress. The next task will be the drafting of a new constitution.

Opposition to the militias has been building since shortly after Gaddafi’s fall. Late last year, militias not based in Tripoli were asked by the transitional government to withdraw from the streets of the capital after residents complained that their neighborhoods had been overrun by young men with guns. A Gallup poll released this month showed that 95 percent of Libyans want to see the militias dissolved. But Friday’s protest was the biggest public showing of anti-militia sentiment to date.

Not all of the militias are rooted in Islamist extremism. But groups such as Ansar al-Sharia have proved a volatile addition to an already contentious debate over the proper role of religion in the new Libya.

Many Libyans, from the liberal elites who dominate the congress to members of the more conservative Muslim Brotherhood, describe their Islam as a moderate and tolerant one. Few — not even Western-educated secularists — say they want a constitution that doesn’t draw from Islamic law.

But the assault on the U.S. Consulate, which American officials now describe as a terrorist attack, has thrown that characterization into sudden and stark relief: Not everyone agrees on what Islamic law — or a state guided by it — actually means.

“There is no doubt that in our societies, we have liberal Muslims who say, ‘I’m a Muslim and I believe Islam belongs only in the mosque,’ ” said Ramadan Eldarsi, a high-ranking official of the Muslim Brotherhood. “But we think that Islam is a broader way to organize people’s lives, not just what they do within a mosque.”

Eldarsi said the Brotherhood differentiates itself from extremist groups such as Ansar al-Sharia in that it advocates peace and tolerance, and believes in the democratic process.

Extremist groups say they are also ready for a fight for the kind of state they want to see. But it’s the tools of that struggle that the moderates say they’re worried about.

At sunset Friday, the anti-militia marchers slowed as they hit a wall of black flags at the edge of Al-Kish Square in downtown Benghazi. A few hundred of Ansar al-Sharia’s followers stood clustered at the entrance to the square, chanting the declaration of Islam: “There is no God but God, and Muhammad is his messenger.”

On the anti-militia side of the crowd, Libyan flags flapped in the wind and someone started blasting pop music from a car.

The mood was tense.

Slowly, some dared to cross the invisible line.

“All of those people are asking for security. But security under what conditions?” said one 19-year-old Ansar al-Sharia member who gave his name only as Mohamed, glancing toward the approaching protest. “There is security under Sharia and there is another kind of security that is created by humans.”

Asked which type Libya is closest to, he responded: “This government is illegitimate.”

Ansar al-Sharia, which formally established itself with a military parade in Benghazi in June, opposes Libya’s transition to democracy, saying the system of elected leadership runs counter to Islamic principles. Ansar al-Sharia acknowledged its members’ involvement in the protest outside the U.S. Consulate but has denied responsibility for the attack.

“It’s a very easy [accusation] to make,” the group’s spokesman, Hany Mansouri, said this week. “People can’t distinguish between the Islamic characters in Benghazi, so it’s easy to use our name.”

Late Friday, the anti-militia protesters overran Ansar al-Sharia’s Benghazi headquarters. But witnesses said the militia members took their guns with them as they withdrew, prompting concerns that the move may be little more than a strategic withdrawal.

At least two people were killed and 30 injured in the clashes, the Associated Press reported, citing hospital sources.

To many, Libya’s religious extremists represent a minority, but an increasingly threatening one in the absence of a strong government security force. That is why many said they framed their anti-militia protest Friday as one calling for rule of law and an end to the right of independent groups such as Ansar al-Sharia to bear arms.

“The Gaddafi regime created a sort of factory for extremism,” said Eldarsi, the Muslim Brotherhood official. “Now the youth have unlimited freedom. They have guns. And they have the wrong thoughts. All of these elements are going to create something negative.”

Barghathy, the professor, said the challenge lies in strengthening a national army and police force, while offering opportunities to young people.

“This is a globalized world, and you can’t just put us back in a bottle,” she said. “We need to do a lot of education and enlightenment. You know, the very first word of the Quran is ‘Read.’ ”