Updated

It began when a Libyan militia paid by Italy to stop migrants heading to Europe intercepted a group of human traffickers offshore. That confrontation has spiraled into a weeks-long battle among rival militias for control of a Libyan coastal city that has left dozens dead.

The bloodshed in the city of Sabratha is in part an unexpected consequence of Europe's effort to stem the flow of migrants from Libya across the Mediterranean. It illustrates how easily things can escalate out of control in the chaos of the North African country, where three different governments claim authority and the real power in many areas lies with local militias.

The Sabratha fight has expanded, bringing in outside factions, including Khalifa Hifter, the strongman who controls eastern Libya and is a rival of the weak, internationally recognized government based in Tripoli, headed by Fayez Serraj. Hifter appears to be using the conflict to obtain a foothold in the western part of the country.

Thousands of families have fled Sabratha, according to the Red Crescent and local officials. Fighting has endangered the city's dramatic antiquity site — the remains of a 1,800-year-old Roman city. At one point, a militia besieged opposing fighters holed up inside the ruins, with snipers positioned on top of the monuments. Photos on line showed bullet holes in one monument.

"This is a war that started between human traffickers, then snowballed into an ideological and political one," said al-Tahar al-Gharabili, head of the Sabratha Military Council, which answers to Serraj's government.

Over the summer, Italy began funneling cash and logistical support to two major militias in Sabratha after they agreed to stop their involvement in human trafficking and instead act as a police force against it, stopping migrant boats. The deal was made through Serraj's government, and the two militias — the Martyr Anas al-Dabashi militia, better known as al-Ammu's militia, and Brigade 48 — were nominally turned into arms of its security forces.

The deal led to a dramatic drop in migration from Sabratha, a city on the western side of Libya's Mediterranean coast that used to be the main launching point for migrant boats.

But voices in Libya decried the deal, fearing that the salaries and supplies would enrich the militias and make them more powerful. The boost to one side threw off the balance of power in Sabratha, triggering a backlash from other local militias.

Al-Gharabili said the conflict began when, last month, a force from the al-Ammu militia clashed with traffickers off shore, thwarting an attempt to move multiple boat-loads of migrants.

The traffickers came from the al-Wadi district, in eastern Sabratha. Because of al-Ammu's crackdown, hundreds of migrants had been stuck in al-Wadi unable to leave, and the traffickers were desperate to move them, al-Gharabili said. "The situation exploded," he said.

The next day, Sept. 17, a paramilitary force allied to al-Wadi opened fire on members of al-Ammu's militia, killing one and wounding others.

Since then, at least 93 people have been killed, including eight civilians, and more than 180 wounded in battles that have carved up the city, according to Essam Karrar, the head of Sabratha Civil Society Federation.

Fighting the past few days has been more intense even than during the 2011 civil war, al-Gharabili said, as militias this week tried to capture al-Ammu's headquarters, a former resort called Shahrazad. Hospitals, hotels and homes have been hit.

The core of the conflict is between al-Ammu and Brigade 48 militias on one side and, on the other, the al-Wadi militia and the Anti-ISIS Operation Room, a force of army officers created to fight the Islamic State group.

All the factions involved are nominally under the authority of Serraj's government — underscoring how little power it actually has over any of them.

Bashir Ibrahim, the al-Ammu spokesman, acknowledged that the deal with Italy was one trigger of the Sabratha fighting. "Certainly, this is among the reasons," he said. "It's about power."

Al-Ammu's opponents depict it as a "terrorist" group linked to Islamist factions and portray themselves as seeking to re-establish state control and stop trafficking.

An al-Wadi spokesman, Hussein al-Alagi, called the Italian deal a "disaster" that reinforces a "bunch of criminals and terrorists."

An Operations Room spokesman, Saleh Graisia, told the AP that the time has come to "remove the tumor that has been growing in Sabratha," referring to the al-Ammu militia.

The fight has grown more complicated as Hifter has thrown his support to the forces fighting al-Ammu. In a statement to the Italian media outlet ADNkronos, HIfter said the fighting in Sabratha was a "legitimate war" against armed groups "that embrace terrorism and human trafficking."

Hifter is backed by the eastern-based parliament that is the rival of Serraj's government, and he has spoken in the past of moving into the west. He has also sought to boost his legitimacy in international eyes, urging Europe to support him as a force to stop migration across the Mediterranean.

A Hifter spokesman, Col. Ali al-Mosmari, vowed on Twitter that the assault would continue "until the whole city is terrorist-free."

Al-Gharabili said Hifter is working closely with the Anti-ISIS Operation Room, something the group's spokesman denies. One of his top commanders recently visited the Operation Room, and another senior Hifter associate recruited men from the area to create a force fighting alongside it, al-Gharabili said.

Also, the al-Wadi militia is believed to be made up of ultraconservative Salafi Islamists known as the Madkhalis who are longtime allies of Hifter in the east. Al-Alaqi said the force is made up of "moderate Muslims" and denied it has direct contact with Hifter, saying they only share "common interests"

Al-Gharabili said he believes Hifter is trying to gain influence in western Libya as leverage in talks with Serraj's government, perhaps ultimately hoping to control of Sabratha, a nearby oil facility and the border crossing into Tunisia further west.

He said Serraj's Defense Ministry has ordered the creation of a force from fighters around the west to move into Sabratha and stop the fighting.

"This is no longer a Sabratha war, it's the entire western region," he said.

It also leaves uncertain the future of Europe's effort to stop migrants by enlisting local forces.

Ibrahim from al-Ammu lamented that fighting has turned brother against brother in Sabratha. Members of the large al-Dabashi family belong to factions on both sides.

"Sabratha is like a mosaic. You arrange it in a way that give you a beautiful picture or in a way that turns very ugly just like now," he said.