Libya's warring factions have signed an agreement on a permanent ceasefire, after five days of talks in Geneva.
The deal between military leaders from Libya's government, and those from opposition forces lead by General Khalifa Haftar, was brokered by the UN.
Its Libya envoy Stephanie Williams called the agreement "a crucial sign of hope for the Libyan people".
Libya has been riven by violence since Col Muammar Gaddafi was deposed by Nato-backed forces in 2011.
The oil-rich nation is a key transit point for migrants heading to Europe from Africa, and many Libyans within the country have been forced from their homes.
AFP quotes the UN's envoy as saying the ceasefire will allow displaced people and refugees inside and outside the country to return to their homes.
Explaining the terms of the deal she said all parties agreed that "all military units and armed groups on the front lines shall return to their camps".
This will be "accompanied by the departure of all mercenaries and foreign fighters from all Libyan territory, land, air and sea within a maximum period of three months from today."
Reporting from Geneva, the BBC's Imogen Faulkes said Ms Williams also warned that a lot of work lay ahead to implement the commitments of the agreement.
The internationally recognised government controls the capital Tripoli and surrounding areas, while forces loyal to Gen Haftar run the eastern part of the country from Benghazi.
When it comes to international backers, Turkey, Qatar and Italy support the Tripoli-based government while the United Arab Emirates (UAE) and Egypt back renegade Gen Khalifa Haftar.
Russia, Turkey, the UAE and other states were accused by the UN last month of blatantly defying the international arms embargo on Libya.
Libya has the biggest oil and gas reserves in Africa.
Since January an armed group loyal to Gen Haftar had blocked key oil fields, causing power cuts and costing Libya billions of dollars in lost exports.
It was partially lifted in August to allow the sale of oil already stored in terminals, but not the production of fresh supplies.
A tall order requiring lasting trust
By BBC North Africa correspondent Rana Jawad
This agreement contains a tall order of requests from both sides - key among these are the withdrawal of troops from frontlines to their respective camps, the removal of the various groups of foreign troops and freezing foreign security agreements.
Implementing this in good faith requires a high degree of trust between the rival sides and a significant shift of foreign policy by the countries involved by proxy, which includes Russia, the UAE, Turkey, and Egypt.
For that trust to materialise, everyone involved would need to work swiftly - and seriously - towards unifying Libya's divided military structures and various militia groups attached to them.
Divisions over the years have resulted in several drawn-out conflicts, even after agreements were reached on paper.
The deal has been met with scepticism by some Libyan observers who see it as an entry point towards potentially tangible, long-lasting peace in the country, rather than a done deal in and of itself.