Three years after Western powers helped Libyan rebels overthrow dictator Moammar Gaddafi, they have at least temporarily abandoned efforts on the ground to bolster Libya’s foundering democracy.

On Wednesday, France evacuated its embassy in Tripoli, where warring militias have traded rocket and artillery fire over the past two weeks in the worst violence in the capital since Gaddafi’s ouster. French ships moved diplomats and French and other European citizens across the Mediterranean to Toulon, just days after U.S. diplomats left by road for Tunisia and then traveled to Malta, where they have set up an embassy-in-absentia.

Although Britain has not formally suspended operations at its Tripoli mission, it has removed all but essential personnel and advised all citizens to leave the country.

The growing turmoil marks a major setback for a country that just two years ago held its first free elections in four decades. What many Western officials hoped would be a democratic rebirth for Libya has instead given way to a battle for power and influence among armed groups who claim to be the rightful heirs of the anti-Gaddafi revolution.

Combatants are broadly divided between Islamist and secular militias. And although the Americans and Europeans are not seen as direct targets of either, some U.S. counterterrorism officials are increasingly concerned that the Islamists could seek to align themselves with al-Qaeda affiliates or with the Islamic State organization that has seized wide swaths of territory in Syria and Iraq.

“You watch, the guys in Libya will want to be a part of it,” a senior U.S. defense official said. Islamic State leader Abu Bakr al-Baghdadi is already attracting support in north and western Africa, he said, and “you’ve got [elements of] AQIM jumping aboard,” he said of al-Qaeda in the Islamic Maghreb, an associate of the core al-Qaeda group.

Other U.S. officials were more sanguine about extremist involvement in the conflict. “We don’t see it as a master plan organized from somewhere else,” one official said.

Militias on the Islamist side of the Tripoli battle, another U.S. official said, “are composed of a mishmash of individuals who by and large are not terrorists, although some members may have terrorist links.”

That is not the case in Benghazi, in Libya’s far east, where different militias, some of which are affiliated with al-Qaeda, are fighting government forces. One of those groups, Ansar al-Sharia, this week overran a Libyan army base, reporting killing dozens of soldiers. Members of Ansar are accused of participating in the 2012 attack on two U.S. government compounds that left U.S. Ambassador J. Christopher Stevens and three other Americans dead.

“What’s going on in Tripoli,” at Libya’s western edge, “is not an AQ-driven fight, but an internal turf battle between liberal and conservative sectors of what is a deeply divided Libyan society,” the second U.S. official said.

The officials spoke on condition of anonymity because they were not authorized to publicly discuss the issue.

The fighting in Tripoli — which Reuters reported was temporarily paused Wednesday to allow firefighters to address the conflagration at a major oil storage depot hit by rocket fire Monday — follows parliamentary elections on June 25.

Islamist groups, never large vote-getters in Libya, performed badly and feared they would be left out of the formation of a new government, according to a European diplomat who closely follows events in North Africa. “Once the Islamists have realized they would be in the minority in the next parliament, and probably not be able to choose the next prime minister,” the diplomat said, “they have chosen to try to derail the process.”

Libyan militias are geographically and tribally based, and the Islamist-dominated group from the Mediterranean city of Misrata has taken the lead, along with allied groups. For their target, they chose the Tripoli airport, territory that in recent years has been under the control of the largely secular Zintan militia, based in that city in southwestern Libya.

“The fight for the airport is an excuse to try to change the balance of power,” the diplomat said. As the two sides began to exchange rocket fire, the U.S. Embassy lay in the path between them.

Although the new parliament is scheduled to convene early next week, there is little optimism that politicians and state institutions, which have virtually no control over militia groups armed to the teeth with weapons seized from Gaddafi’s armories, will be able to rein in the violence.

As the United States evacuated its embassy over the weekend, some Republican lawmakers charged that Libya was just one more foreign policy crisis over which the Obama administration had lost control.

“This deteriorating security posture is the same scenario playing out across North Africa, the Middle East and Eurasia,” said the chairman of the House Intelligence Committee, Rep. Mike Rogers (R-Mich.). “This is what happens when the United States is not engaged and lacks a clear foreign policy that includes strong U.S. leadership.”

Rep. Edward R. Royce (R-Calif.), the chairman of the House Foreign Affairs Committee, said the departure of U.S. diplomats was probably the “right call,” given the chaotic security situation. But “our diplomatic absence will make the hard task of achieving political stability in Libya even harder.”

U.S. officials privately stress the challenges of influencing the situation.

“I think there is an exaggeration of what the international community can do,” a senior administration official said. “We certainly hear from the Libyans — ‘Can you guys come in here and fix everything?’ That’s just not the way democracies are formed.”

U.S. officials are working through David Satterfield, the administration’s special envoy for Libya, and with other governments with influence over the two sides to press for them to stop fighting. “We continue to have all the support in place” for the Libyan government, the senior official said. Once a new parliament is seated, “support is available for the Libyans as they need it. But this is fundamentally a Libyan-led effort. . . . They’re the ones who are going to have to make these compromises.”

The European diplomat expressed doubt that early progress was likely. “We’re paid to be optimistic and make things happen,” the diplomat said. But “if you want to bet one pizza with little risk, you can bet that things will not be resolved in the next couple of days.”

Greg Miller contributed to this report.