Armed groups in Tripoli have signed a ceasefire deal ending a four-day battle for control of the Libyan capital, the unity government said Thursday.
The city has been paralysed amid exchanges of rocket and artillery fire between pro-unity government forces and rival militias including groups allied with former prime minister Khalifa Ghweil.
Thursday's deal cements the UN-backed Government of National Accord's control over large parts of the capital.
It provides for an "immediate ceasefire" and calls for armed groups that do not recognise the GNA to leave Tripoli within 30 days.
It also demands the release of people arrested since Monday, the GNA's defence ministry said.
Clashes on Wednesday night rocked the capital's southern Salaheddine district, where several rival militias occupy barracks.
But the city and its surroundings were quiet on Thursday morning following the overnight deal, signed by the GNA, local mayors and powerful militias from Tripoli and Misrata.
Militias have been key power brokers in a country plagued by violence and lawlessness since the NATO-backed ouster of longtime dictator Moamer Kadhafi in 2011.
The battle, triggered Monday night after the killing of a bank guard, saw pro-GNA forces expand their clout in the capital.
They took several districts from rival militias including groups allied with Ghweil, who was forced out of power when the GNA arrived in Tripoli.
The GNA operation appeared to be well-prepared and coordinated. Thursday's deal charges GNA forces with securing areas controlled by rival groups.
Observers said it was in line with an inter-Libyan political deal backed by the UN and signed in December 2015.
That agreement, which gave rise to the GNA, called for armed groups to leave Tripoli and other Libyan towns.
The capital remains home to dozens of militias. Since taking office, the unity government has secured the backing of several, but many parts of Tripoli remain out of its control.
The GNA wants to see heavy weapons withdrawn from the capital to allow its security forces to operate effectively.