BENGHAZI, Libya -- Islamic hard-line militias, including the group accused by the United States in a 2012 attack that killed the ambassador and three other Americans, claimed control of Libya's second largest city, Benghazi, after overrunning army barracks and seizing heavy weapons.

The sweep in the eastern city is part of a new backlash by hard-liners against their rivals ahead of the sitting of a new parliament. In the capital Tripoli, escalating battles Thursday between militias prompted multiple foreign governments to scramble to get out their citizens as thousands of Libyans fled across the border into Tunisia.

The weeks-long surge of violence renewed fears that Libya, which has been in chaos since the 2011 civil war that ousted longtime dictator Moammar Gadhafi, is plunging deeper into civil strife.

With a crippled central government and weak army and police, the country's numerous rival militias have held sway in Libya for the past three years. Though they battled each other frequently, a balance of fear among them prevented any from going too far and forced them to divide areas of power. But now, there militias led by Islamist and extremist commanders appear to be trying to gain a more decisive upper hand.

The Health Ministry said in a statement Thursday that the death toll in Tripoli since violence intensified the past month reached 179, with more than 700 people wounded.

Militias allied to Islamist politicians have been fighting for weeks to wrest control of Tripoli's airport from rival militias, destroying much of the airport in the process. On Thursday, witnesses said that random rocket fire hit houses and vehicles in western Tripoli, sending residents fleeing. Shelling hit a funeral in a southern district, killing four children and three women from a single family, security officials said, speaking on condition of anonymity because they were not authorized to talk to the press.

Thursday evening, thousands of residents marched into Tripoli's central Martyrs Square in a protest denouncing militias. They raised banners reading, "Libya only" and "Enough bloodshed."

Tripoli residents said fuel and gasoline shortages were worsening, and food prices had leaped. "All of this is caused by political parties that are fighting for power," said Abdelfattah Alghanai, a man shopping for vegetables.

By noon on Thursday, more than 10,000 Libyans fled by land across the border into neighbouring Tunisia over the previous 12 hours, Tunisia's state news agency reported. They joined thousands of other Libyans who have already streamed into Tunisia in recent days. Spain announced it was pulling its ambassador and most embassy staff out of Tripoli, a step already taken by the United States. China has chartered a Greek vessel to evacuate hundreds of Chinese citizens, and the Philippines is working to get out some 13,000 Filipino workers inside Libya.

The militias' moves in both Tripoli and Benghazi reflect an attempt to "rearrange the equilibrium," said Frederic Wehrey, an analyst from the Carnegie Endowment for International Peace.

It was prompted by two factors, he said. One was June parliament elections, in which Islamist political factions are believed to have lost their dominance over parliament. There is also a strong element of regional divisions in the fighting: The militia fighting to capture the airport is from the western city of Misrata, allied to Islamist politicians, while the militias defending it are from the western town of Zintan.

The other factor was an offensive launched earlier this year by a renegade general, Khalifa Hifter, who vowed to crush Islamic hard-line factions. Numerous units in the weak and fragmented army pledged loyalty to him, as did some militias, and his forces have been attacking hard-line militias in Benghazi.

Islamic militias in Benghazi responded in June by forming an umbrella group called Shura Council of Benghazi Revolutionaries, made up of multiple armed factions led by Islamic extremist commanders.

Among the factions is Ansar al-Shariah, the group accused by the United States of leading a Sept. 11, 2012 attack on a diplomatic facility in the city that killed the ambassador and three other Americans.

For weeks, the coalition has been battling back. The past week, the coalition's fighters overran five major army barracks, most importantly including the barracks of the Special Forces, the strongest government force in the city, which backs Hifter.

The extent of the militias' control over Benghazi was not clear. Military officials denied militia control, and it appeared the fighters had withdrawn from some of the barracks after looting them. Hifter loyalists continue to control Benghazi's airport, but appeared to have been driven out of the city.

On Thursday, the city's streets were nearly empty, with residents staying indoors and no sign of checkpoints by either militiamen or security forces. The main police headquarters was still smouldering after it was hit by militia shelling a day earlier, and smoke rose from the barracks of the Special Forces.

"We are the only force on the ground in Benghazi," a commander of one of the coalition's factions told The Associated Press on Thursday. He spoke on condition of anonymity because he was not authorized to talk to the press. He said the coalition's fighters had driven all army forces and fighters loyal to Hifter out the city.

Ansar al-Shariah's commander, Mohammed al-Zahawi, proclaimed victory in a video released by his group late Wednesday. Speaking in front of a tank inside the Special Forces base, he urged Hifter's allies to abandon him, accusing him of trying to "loot the fortunes of Libya" and put the country under the influence of the West.

Another militia commander, Wissam bin Hamid, was also shown in the camp in the video, proclaiming in front of his masked fighters, "We will not stop until we establish the rule of God."

On its Twitter account, Ansar al-Shariah posted photos said to show its fighters taking large amount of weapons and ammunitions from the bases, including rockets, hundreds of brand new assault rifles, and shoulder-fired anti-tank rockets. Militiamen drove bulldozers and other vehicles from inside the barracks, videos showed. The photos and videos conformed with the AP's reporting from the city.

The new parliament is supposed to convene by Monday, but it is unclear where it would do so, with both Tripoli and Benghazi in turmoil. There has been talk of holding it in the eastern city of Tobrouk, a power base for Hifter. All candidates in the election had to run as independents, so the political leanings of the winners are not certain, but it is widely believed Islamist politicians lost their earlier dominance.

Ashur Shway, a former interior minister and now a professor at Benghazi University, said Islamic militias were trying to prevent parliament from meeting. "The bottom line is that those who lost elections want to make gains on the ground," he said.