But Ansar al-Sharia is edging back into society, and many Benghazi residents say they want it here.
The militia tentatively resumed its role as guardian of Benghazi’s two main hospitals last week. Its fighters have staked out positions at the western entrance to the city. They also have moved back onto their base and residents say the group has been participating in community cleanup and charity work.
Its resurgence — and that of Rafallah al-Sahati, another Islamist militia — underscores the city’s reckoning with a harsh reality, residents said.
No one else is capable of securing volatile Benghazi.
On Sunday, Libyan leader Mohammed el-Megarif called for unity as the nation celebrates the second anniversary of the uprising that toppled dictator Moammar Gadhafi but plunged the country into lawlessness and economic woes.
Addressing thousands of flag-waving Libyans in the city that was the birthplace of the anti-Gadhafi uprising, Mr. el-Megarif urged his countrymen to “join ranks and resolve our differences to build our nation.”
He also promised to fight poverty and “marginalization,” and to give Libyans cash to mark the ouster. He did not say how much money or how it would be distributed.
Libya has been roiled by instability and violence since the ouster of the Gadhafi regime in 2011. Benghazi has been among the worst-hit parts of the country, falling prey to armed militiamen and Muslim militants.
Mr. el-Megarif alluded to the rise of radical Islam in the energy-rich nation, vowing he would not allow Libya to become “an incubator of terrorism and violence.”
In what appeared to be an attempt to assuage the militants, the Libyan leader promised that the nation’s next constitution would explicitly declare Islam as the country’s religion and that Islamic law would be the main source of legislation.
Sunday’s celebration was held amid tight security precautions.
Army vehicles blocked roads leading to the site and snipers deployed on nearby rooftops.
In Tripoli, tens of thousands thronged the main square in celebration.
The eight-month war that toppled Gadhafi left the country awash with weapons and brigades of former revolutionary fighters, many of whom now operate as militias loosely allied with the government and determined to play a security role in the new Libya.
Thousands of Benghazi residents protested against the militias and the prevailing lawlessness in the aftermath of the Sept. 11, 2012, attack on the U.S. mission, and some locals assisted by government-allied militias overran bases belonging to Ansar al-Sharia, Rafallah al-Sahati, and two other groups.
But the country’s police force, much of it stocked with men who served under the ousted regime, has continued to face opposition from the militias.
After Ansar al-Sharia left its post as the self-appointed guardian of Jelaa Hospital in Benghazi, security rapidly deteriorated there, health officials said.
Feuds between families carried from the streets into the emergency room.
Patients sold drugs in the hallways and stole hospital equipment.
Doctors were sometimes threatened at gunpoint, said Mohamed Khamis, an emergency room surgeon. Last month, a militia member walked into the emergency room and shot his rival dead on the operating table, he said.
“After that, we closed for two weeks. We called for help. We reached out to the Interior Ministry and the Health Ministry, but all they’ve done is make promises,” Dr. Khamis said.
Last week, the hospital finally reopened its doors — but only after a security force made up of Ansar al-Sharia alumni and neighborhood fighters took up positions outside.
Ansar al-Sharia’s black flag flies above the main entrance.
For the last four days, no violent incursions have occurred, Dr. Khamis said.
“The people attacked Ansar al-Sharia a few months ago because they were angry. But now they’re asking them to come back because there is no police and no real military,” said Essam al-Zubeir, a government spokesman in Tripoli.
If the residents of Benghazi have learned a hard lesson about security and the capabilities of their weak central government, so too have the militias learned from the people, many said.
Ambassador Christopher Stevens “was a great friend of the revolution and his death was a great blow. But what came out of it was the toning down of the extremists,” said Essam Gheriani, a businessman and activist.