Two rival Libyan leaders have committed themselves to a ceasefire, working towards elections and finding a roadmap to secure the country against terrorism and trafficking of all kinds, according to a document released by the French presidency.

The meetings at a chateau in La Celle Saint-Cloud, west of Paris, brought together Fayez Serraj, prime minister of the UN-backed unity government, and General Khalifa Hifter, the Egyptian-backed commander of Libya's self-styled national army.

French President Emmanuel Macron met with each separately ahead of an encounter between the two Libyans in the presence of the UN's newly appointed special envoy for Libya, Ghassan Salame.

"There is political legitimacy in the hands of Mr Serraj. There is military legitimacy in the hands of Mr Hifter. They have decided to work together," Mr Macron said.

The 10-point joint declaration that capped the encounter was the first of its kind since Libya spiralled into chaos after the 2011 toppling and killing of leader Muammar Gaddafi.

Among the points agreed upon was a commitment to a ceasefire, with armed force reserved "strictly" for use in counter-terrorism operations.

The rivals also "solemnly commit to work towards the holding of presidential and parliamentary elections as soon as possible".

The French president said later that the goal is for balloting in the spring.

Mr Serraj had said in May that elections would be held in spring.

"The stakes of this reconciliation are enormous. Enormous for the Libyan people, who have been suffering, living with instability and terrorist threats these past years, and it is considerable for the whole region," Mr Macron said after the talks.

"Because if Libya fails, the whole region fails with it, especially directly neighbouring countries.

"And it is a process that is essential for all of Europe because if we don't succeed, the consequences affect our countries directly because of the terrorist risk and migration consequences."

Mr Macron's bid to work towards laying the groundwork for a state with a functioning government and institutions is a priority of his presidency.

Talks were centred on creating a propitious climate for elections next year - which the Libyan prime minister announced plans for in May - security and military issues, respect for human rights and economic development of the oil-rich nation where residents struggle despite the resources, French officials said.

Mr Macron, Mr Salame and Mr Serraj, along with French foreign minister Jean-Yves Le Drian, walked into the chateau to begin the first set of talks after shaking hands before Republican Guards in their ornate gear. Gen Hifter arrived later.

The encounter was never expected to resolve the knotty problems of Libya, politically fractured and awash with militias and human traffickers preying on migrants who use the Libyan coast as a jumping off point to Europe, mainly Italy.

But it was seen as a way to lay the basis for the UN envoy to come up with proposals in the weeks and months ahead.

Mr Serraj and Gen Hifter met in early May in Abu Dhabi, and the United Arab Emirates said later there had been a "significant breakthrough".

Libya TV said the men agreed on holding presidential and parliamentary elections next year.

Paris has made clear that the French initiative is not meant to brush aside numerous initiatives by others, including the European Union, the African Union and individual countries, such as Morocco.

France "wants to facilitate a political entente" and "mark its support for efforts to build a political compromise, under the auspices of the United Nations", that includes all actors in the country, a statement on Monday by the president's office said.

The challenge, it added, is to "build a state capable of responding to the fundamental needs of Libyans" with one regular army "under the authority of civilian power", considered necessary for the control of borders and stability within Libya.

Sign up to our free newsletters

Get the best updates straight to your inbox:
Please select at least one mailing list.

You can unsubscribe at any time by clicking the link in the footer of our emails. We use Mailchimp as our marketing platform. By subscribing, you acknowledge that your information will be transferred to Mailchimp for processing.