Libya’s UN-backed Government of National Accord (GNA) has regained full control of Tripoli after recapturing the capital’s airport.
Gen Khalifa Haftar’s forces have been besieging the city since April 2019.
But intensified military support from Turkey helped government forces drive Gen Haftar’s Russian-backed troops back from the frontlines.
A new diplomatic effort is under way to try to restart talks on a lasting ceasefire in the oil-rich nation.
The recapture of the international airport in Tripoli – long out of use – is the strongest symbolic victory for the Libyan government so far, reports the BBC’s Arab affairs editor Sebastian Usher.
Libya has been torn by violence since long-time ruler Col Muammar Gaddafi was deposed and killed in 2011 by Nato-backed forces.
- Africa Live: Updates on this and other news stories
- Russia and Turkey risk turning Libya into another Syria
- Why is Libya so lawless?
- Khalifa Haftar: The Libyan general with big ambitions
By Rana Jawad, BBC North Africa correspondent
Some of the biggest hurdles to resolving the conflict in Libya have been the involvement of a multitude of countries by proxy, the continued arms flow despite a long-standing UN embargo, and the belief that a military victory allows any warring side to consolidate power.
The internal power shift is often brief until the next battle rolls in.
Libya’s short and protracted battles have come and gone over the years and no matter who claims victory at the end of each one, the essence of the problem remains largely unchanged.
The internationally recognised government and the forces fighting for them never really lost control of Tripoli after Gen Haftar launched an attack on it, but they were struggling to maintain it over the past year until they received overt military backing from Turkey.
There is a sense of deja vu over Libya’s various conflicts for good reason – time and again, following any respite from war, there is a pause, re-grouping, and political talks, often followed by new armed group alliances and another battle.
A long-term resolution ultimately lies in Libyan hands and a resolve to put an end to the bloodshed and power grabs – everything else is secondary.
A military source with Gen Haftar’s forces, whose base is in the eastern city of Benghazi, said they were pulling back from all of Tripoli’s suburbs, reports the Reuters news agency.
The GNA advance follows reports last month that mercenaries from the Russian Wagner Group, who had been fighting with Gen Haftar, were evacuating from Libya, although this was never confirmed.
In early May, a leaked UN report said that hundreds of mercenaries from the Wagner Group – run by Yevgeny Prigozhin, a close associate of President Putin – were operating in Libya.
Gen Haftar is also backed by the United Arab Emirates and Egypt, while the GNA enjoys the support of Turkey, Qatar and Italy.