When the head of Libya’s UN-backed Government of National Accord suspended the interior minister from his duties at the end of August, militias in Tripoli celebrated by firing weapons in the air. But two days later, when Fathi Bashagha flew back to the city after returning from a visit to Turkey, rival militias gave him a hero’s welcome and  paraded in convoys through the streets.

Under pressure from the UN, Turkey and the other foreign powers that back the GNA, Mr Bashagha and Fayez al-Sarraj, who heads the government, patched up their differences and the minister was reinstated. But the public rift and scenes of rival armed groups on the streets highlight the fragility of the alliance that underpins the GNA and threatens efforts to forge peace in the divided North African oil exporter, analysts and diplomats warn.

Libya is broadly split between rival administrations: the GNA, which governs the west, and an eastern-based parliament aligned with renegade general Khalifa Haftar, who wants to seize power across the country. But all factions are dependent on militias that have exploited nearly a decade of chaos to fill the vacuum. Although in Tripoli they helped protect the city after Gen Haftar launched his offensive on the capital in April 2019, they have for years been accused of behaving like criminal gangs, engaging in extortion and plundering state funds. At times they have turned their guns on each other.