CAIRO/TRIPOLI (Reuters) - A bout of fighting in Libya's capital has laid bare the fragility of a militia cartel that had brought a veneer of stability to the city and encouraged the gradual return of foreign diplomats and plans for elections in December.
Major battles have become rarer in Tripoli since last year as a handful of armed factions aligned with the internationally recognised Government of National Accord (GNA) consolidated their control.
But the ascent of four or five "super militias" has created resentment among groups excluded from the capital and from access to the spoils of Libya's informal economy.
That has heightened the risk of conflict and made the challenge of disbanding militias or integrating them into regular security forces more complex, diplomats and analysts say.
Bringing militias to heel is seen as crucial to resolving a conflict that has divided Libya since a NATO-backed uprising forced Muammar Gaddafi from power seven years ago, slashing oil production and giving space to migrant smugglers and militants.
Fighting on Monday and Tuesday pitted the Seventh Brigade, or Kaniyat, from Tarhouna, a town 65 km (45 miles) southeast of Tripoli, against the Tripoli Revolutionaries' Brigades (TRB) and the Nawasi, two of the capital's largest armed groups.
The Kaniyat and other groups from outside Tripoli have noticed the success of rivals inside the city with growing unease. Reports about the wealth, power and extravagant lifestyles of some Tripoli militia commanders have fuelled resentment.
"The profits from state capture now go to a narrower set of armed groups than ever before," said Wolfram Lacher, a researcher at the German think-tank SWP.
"That's a very dangerous situation because it excludes powerful forces from access to levers of the state and administration, and this is now causing those forces to build alliances against the big militias in Tripoli."
As they launched their incursion into Tripoli, Kaniyat denounced their rivals as the "Daesh (Islamic State) of public money", promising to "cleanse" them from the country.
Kaniyat made gains as tanks, armoured vehicles and pickup trucks mounted with anti-aircraft guns were deployed in densely populated residential areas of southern Tripoli, with explosions and heavy artillery fire echoing across the city.
At least five people were killed and nearly 30 wounded on the first day, officials said.
Tripoli's big armed groups claim official status through the GNA - which is opposed by a rival government and military faction based in the east of the sprawling North African country - but act with autonomy.
They guard strategic buildings, control Tripoli's airport and have infiltrated ministries and many of the banks, giving them access to coveted dollars at the official exchange rate, about five times cheaper than the parallel rate.
"They place their people throughout the state administration, particularly in positions that offer control of economic resources," said Lacher.
Since last summer an ex-prime minister, the mayor of Tripoli and the head of the state religious authority have been among a series of senior figures to be abducted then released by militias.
A key member of the GNA's leadership, Fathi al-Majbari, withdrew from his position after an armed group attacked his residence in June.
Earlier this month the National Oil Corporation denounced militia threats against the newly appointed head of its fuel distribution unit over efforts to tackle smuggling, and the sovereign wealth fund said that it had been forced by threats and abductions to move premises.
Prominent Libyans based abroad have said they seek the protection of armed militia factions, not the government, when they travel to Tripoli. Diplomatic staff evacuated amid fighting in 2014 and now tentatively returning ultimately depend on armed groups for access and protection.
Critics of a French-led plan to hold national elections on Dec. 10 worry that a free vote will be impossible, and that militias will challenge with force any result they don't like.
"I think it's a race against time and I feel like the (Libyan) state's disappearing," said one senior diplomat. "It's hard now to tell where's the state and where's the militia."
Gaddafi's four-decade-long, one-man dictatorship left Libya with few effective state institutions after his overthrow.
(Writing by Aidan Lewis; Editing by Mark Heinrich)