* Headquarters of Islamist Ansar al-Sharia group targeted
* Group was linked to last week's attack on U.S. consulate
* Crowd also attacked pro-government militia
By Peter Graff and Ghaith Shennib
BENGHAZI, Libya, Sept 22 (Reuters) - The two main Islamist militias in Derna, a city in eastern Libya known as an Islamist stronghold, withdrew from their five bases on Saturday and announced they were disbanding, residents said, a day after a militia was driven out of Benghazi.
The Abu Slim and Ansar al-Sharia militias' announcements were apparently motivated by events in Benghazi, where Ansar al-Sharia, a group linked with last week's deadly attack on the U.S. consulate, withdrew from all its bases in the city late on Friday amid mass demonstrations in support of the government.
Those demonstrations in Libya's second city, also in the east, erupted into violence when the crowd turned against another group that had sworn support for the government.
"The militia in Derna saw what happened last night and they decided: we will not kill our brothers. So they disbanded," Siraj Shennib, a 29-year-old linguistics professor who had been part of protests against the militia, said by telephone. "They said they no longer exist as militias in Derna. They will go home and leave security to the interior ministry and army."
Shennib said anti-militia protesters had been maintaining a vigil against the groups in Derna for 10 days, and the protests became much larger after a car-jacking three days ago. Residents blame the militia for creating a climate of insecurity.
"The people started coming because it has reached the limit. They are saying: we've had enough," he said. "It was a very peaceful operation. We are happy and we appreciate the effort the militias have done to save people from conflict."
Libyan LANA news agency quoted commanders from both militias as saying they were disbanding and vacating their compounds.
Abu al-Shalali, 27, an Abu Slim fighter who trained as an electrical engineer, said there was a non-violent confrontation at one camp between protesters and fighters who did not initially want to leave but ultimately decided they could not use force against the crowd.
"We can't kill our brothers and our cousins," he said, adding that camp housed a jail with 50 prisoners, all of whom were freed. He said they were common criminals and that their release would probably cause a crime spree.
Derna, a coastal city overlooking the Mediterranean, is known across the region as a major recruitment centre for fighters who joined the wars in Iraq, Afghanistan and Syria.
Shennib said the city's reputation was an exaggeration.
"Yes, we have a group of people who are jihadis. But it's not very dangerous at all. It's a normal city. And no one would say that it's a base for al Qaeda. That's just talk," he said.
Ansar al-Sharia was driven out of Benghazi in a surge of anger against the armed groups that control large parts of Libya more than a year after the overthrow of Muammar Gaddafi.
A spokesman for Ansar al-Sharia, which has been linked to the attack on the U.S. consulate in Benghazi in which the U.S. ambassador and three other Americans were killed, said it had evacuated its Benghazi bases "to preserve security in the city".
In a dramatic sign of Libya's fragility, after sweeping through Ansar's bases the crowd went on to attack a pro-government militia, believing them to be Islamists, triggering an armed response in which at least 11 people were killed and more than 60 wounded.
The invasion of Ansar al-Sharia's compounds, which met little resistance, appeared to be part of a sweep of militia bases by police, troops and activists following a large demonstration against militia units in Benghazi on Friday.
Demonstrators in Benghazi pulled down militia flags and set a vehicle on fire inside what was once the base of Gaddafi's security forces. Hundreds of men waving swords and even a meat cleaver chanted "Libya, Libya", "No more al Qaeda!" and "The blood we shed for freedom shall not go in vain!"
"After what happened at the American consulate, the people of Benghazi had enough of the extremists," demonstrator Hassan Ahmed said. "This place is like the Bastille. This is where Gaddafi controlled Libya from, and then Ansar al-Sharia took it over. This is a turning point for the people of Benghazi."
Speaking in Benghazi, the head of Libya's national congress Mohammed Magarief said state security forces had agreed to form a "security operation room" which would work to secure Benghazi by dissolving militias not under the control of the government.
Calling for weapons not to be carried in public, he said it would also prohibit checkpoints and patrols made by illegitimate groups and allow the army to take control of compounds belonging to pro-government militias.
PRESSURE ON OBAMA
Libya's government had promised Washington it would find the perpetrators of what appeared to be a well-planned attack on the U.S. consulate, which coincided with protests against an anti-Islam video and the anniversary of the 9/11 attacks.
The attack and the outrage directed at the United States over the video across the Muslim world raised questions about President Barack Obama's handling of the so-called Arab Spring.
Although Ansar al-Sharia denies any role in the consulate attack, the latest events in the cradle of Libya's revolution appeared at least in part to vindicate Obama's faith in Libya's nascent democracy.
"It's a pretty clear sign from the Libyan people that they're not going to trade the tyranny of a dictator for the tyranny of the mob," said White House spokesman Josh Earnest.
Libyan political scientist Ahmad al-Atrash told Reuters: "People in Benghazi and all over Libya want to get these militias under control ... The overwhelming feeling is against any element that keeps the situation unstable."
The second half of Friday night's protest proved his point.
A crowd swelling into the thousands moved on to attack a separate Benghazi compound where the powerful pro-government Rafallah al-Sahati militia, safeguarding a big weapons store, opened fire on the assailants.
As looters later tried to leave the scene, vigilantes wielding clubs and machetes tried to prevent them driving off with heavy weapons. Hospital officials told Reuters they had a total of five dead and more than 60 wounded.
Police found six more dead bodies near the compound on Saturday morning, police officer Ahmed Ali Agouri said.
The six dead men were bodyguards of a colonel in the regular Libyan army who went missing on Friday, and the prospect that the killings and kidnapping may have been the work of a militia group suggested there could be more tension between the army and militia in coming days.
Nasser Abdelhaaq, a Rafallah al-Sahati commander, said the brigade had returned to their compound on Saturday morning.
He suggested the crowd had been deliberately manipulated to turn on Rafallah al-Sahati, an officially approved militia that also has Islamist leanings.
RELIANT ON MILITIAS
"Twenty-five percent of those who came were there as saboteurs," he said. "Some of them, we know who they are, they were working with Gaddafi's security brigades."
Libya's new rulers know that while militias pose the biggest threat to their authority, the state's weak security forces rely on former rebel units, armed with heavy weapons, that fought in the uprising.
Like the rest of Libya, Benghazi is still prowled by dozens of armed groups operating openly, usually with the official permission of a government that is powerless to stop them.
Ansar al-Sharia's overt Benghazi presence was never huge. Its leaders proclaim democratic government to be incompatible with Islam, and the presence on the streets of pickup trucks bearing their Kalashnikov logo was an affront to the government's authority.
But a doctor in a hospital where Ansar al-Sharia had been providing security for the past six weeks said the group had prevented anarchy.
"I don't know about their religion or ideology, but they solved problems," said Abdulmonin Salim. "I don't care if they come from another planet. I want a secure hospital."
The U.S. consulate attack seems to have provided a strong impetus for local authorities to rally support behind the weak government. Thousands marched in Friday's "Rescue Benghazi Day" in support of democracy and against Islamist militias.
U.S. Ambassador Stevens was well liked, and many Libyans condemned the attack despite being angered by the anti-Islamic film made in California that triggered it.
Derna, Libya Islamist Militias Swept Out Of Bases