BENGHAZI, Libya -- Islamic hard-line militias, including the group accused in a 2012 attack that killed the U.S. 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, 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 in the past month reached 214, with more than 981 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 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.

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 Thursday, more than 10,000 Libyans had fled by land across the border into neighboring 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 Thursday that it was pulling its ambassador and most of its 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.

The other factor was an offensive launched earlier this year by a renegade general, Khalifa Hifter, who vowed to crush Islamic 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, 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 continued to claim control Benghazi's airport but appeared to have been driven out of the city.

"We are the only force on the ground in Benghazi," a commander of one of the Islamic coalition's factions said Thursday. He spoke on condition of anonymity because he was not authorized to talk to the media.

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.

Information for this article was contributed by Derek Gatopoulos and Bouazza Ben Bouazza of The Associated Press.