Tunisian taxi drivers wait for clients fleeing from Libya at the Ras Ajdir border post between Libya and Tunisia, Thursday. Up to 6,000 people a day have fled Libya into neighboring Tunisia this week, the Tunisian foreign minister said Wednesday, the biggest influx since Libya’s 2011 civil war, in a sign of the spiraling turmoil in Tripoli.

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 their citizens out 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, the 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 the 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 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.

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 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 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.