CELLE-SAINT-CLOUD, France (Reuters) - Libyan Prime Minister Fayez al-Serraj and the divided country’s eastern commander Khalifa Haftar committed to a conditional ceasefire and to work towards holding elections next spring in talks chaired by French President Emmanuel Macron on Tuesday.

Slideshow ( 5 images )

Past attempts at peace deals in oil-producing Libya have often been scuttled by internal divisions among the myriad of competing armed groups that have emerged since rebels toppled strongman Muammar Gaddafi in 2011.

“We commit to a ceasefire and to refrain from any use of armed force for any purpose that does not strictly constitute counter-terrorism,” the rivals said in a rare statement agreed in the second encounter between the rivals since talks in Abu Dhabi in May that produced little concrete progress.

Serraj and Haftar agreed to work to hold elections as soon as possible under U.N. supervision, the document added. Macron said they had agreed on spring next year.

Western governments are pushing a U.N.-backed political agreement to unify the country under which Serraj’s Tripoli-based government was installed. One key sticking point has been the role Haftar could play and who would control Libya’s army.

“There is political legitimacy. That is in the hands of Mr al-Serraj. There is military legitimacy - that of commander Haftar. They have decided to act together. This is a powerful act,” Macron told reporters after the two Libyan rivals shook hands, smiling, in front of cameras.

“They have the legitimacy and capacity to gather around them all those who want to be involved in a political process of reconciliation and construction of peace.”

The statement was in line with a draft circulated earlier on Tuesday by the French presidency.

Macron said on July 13 there would be concrete diplomatic initiatives on resolving the Libyan conflict soon.

He wants France to play a bigger role in coaxing Libya’s factions to end the turmoil that has allowed Islamist militants to gain a foothold and migrant smugglers to flourish in the absence of a strong central government.

Haftar, who this month declared victory over rival armed groups in the battle for Libya’s second city Benghazi, has refused to accept the government’s legitimacy. He has been gaining ground backed by allies Egypt and United Arab Emirates.

Serraj is backed by Haftar’s rivals, armed brigades in the western city of Misrata, and by some factions in Tripoli. But he has struggled to extend his government’s influence and faces resistance from some hardliners in the capital.

French officials fear Islamic State militants - who were driven from the coastal city of Sirte last year - and other jihadists could try to exploit the power vacuum in Libya to regroup after losing substantial ground in Syria and Iraq, and see this a window to push the sides closer together.

But the French initiative to hold these talks has angered officials in Italy, which has previously taken the lead in efforts to bring peace to its former North African colony and borne the brunt of successive waves of African migrants who have crossed the Mediterranean from Libya.

Italian Foreign Minister Angelino Alfano on Tuesday told La Stampa newspaper he supported the French initiative. But he added: “There are too many open questions on Libya, too many mediators, too many initiatives ... we need to combine our efforts and focus them on (U.N. envoy for Libya Ghassan) Salame.”