By Madeline Chambers and Ece Toksabay

BERLIN (Reuters) - A Libyan military commander waging an offensive to capture the capital Tripoli is committed to a ceasefire, Germany said on Thursday, in an apparent advance for efforts to end a near-decade of turmoil in the North African country.

German Foreign Minister Heiko Maas, after visiting the eastern Libyan city of Benghazi, also said commander Khalifa Haftar is willing to attend a conference in Berlin on Sunday about the conflict.

Haftar's office was not available for comment. But three sources close to the matter told Reuters that Haftar was expected to have talks in Athens on Friday with Greece's prime minister and foreign minister during a stopover on his way to Berlin.

Maas's comment follows failed efforts by Russia and Turkey to persuade Haftar on a visit to Moscow this week to agree to a lasting ceasefire and halt the offensive on Tripoli. Haftar left Moscow without signing the proposal.

The nine-month-old war over Tripoli is just the latest bout of chaos in Libya, an OPEC member that has become a hub for human traffickers to ship migrants by boats to Italy, while Islamist militants have exploited the widespread disorder.

"If developments in Libya are allowed to continue, then Libya will be the next Syria and we don't want that to happen," Maas said later on German television.

The conference to be hosted by Germany on Sunday would bring together Libyan rival camps and the foreign powers that support them to try to end the war over Tripoli and resume talks on a power sharing deal.

Among those attending would be Russian President Vladimir Putin, Turkish President Tayyip Erdogan, U.S. Secretary of State Mike Pompeo and European leaders, Maas said.

"General Haftar has signalled his readiness to contribute to the success of the Libya Conference in Berlin and is willing to participate. He has repeated his commitment to observe the existing ceasefire," Maas said in a tweet sent by his ministry.

German Chancellor Angela Merkel welcomed the move and said the conference aimed to get parties to honour a weapons embargo.

"At the Libya conference we must above all see that the weapons embargo is adhered to again, which is basically agreed by the U.N. but unfortunately not honoured," she told reporters.

Maas said on German television that after a ceasefire and arms embargo had been observed, a political process must take place under the auspices of the United Nations to give Libya a prospect of ending its civil war.

OUTSIDE POWERS

Libya has been fractured and deeply unstable, with outside powers providing support to rival armed factions since veteran dictator Muammar Gaddafi was toppled in a 2011 uprising.

Turkey backs Fayez al-Serraj's internationally recognised Government of National Accord (GNA) while Haftar - whose forces control much of Libya's east and south - has received support from Egypt, the United Arab Emirates, Jordan and Russian mercenaries.

Turkey is beginning to send troops into Libya in support of Serraj's government, President Tayyip Erdogan said on Thursday.

"In order for the legitimate government in Libya to remain standing and for stability to be established, we are now sending our soldiers to this country," Erdogan told an event in Ankara.

Greece is furious at the pact between Turkey and Serraj's government as it seeks to map out a maritime boundary that skims the Greek island of Crete and which Greece and allies say is contrary to international law. Maritime boundaries could give nations the right to explore for hydrocarbons in an as-yet untapped part of the Mediterranean.

Greece says it will exercise a European Union veto on any peace pact in Libya that does not void the Turkish-Libyan deal.

(Additional reporting by Michele Kambas and Renee Maltezou in Athens; Writing by Ulf Laessing; Editing by William Maclean, Mark Heinrich and Grant McCool)