Turkey's recent moves with Libya -- threatening troop deployments and signing a contentious maritime deal -- are aimed at shoring up a rare regional ally and preserving access to gas supplies, analysts say.
Ankara has been one of the staunchest supporters of the beleaguered Government of National Accord (GNA) in Tripoli, a relationship that has deepened in the face of an assault to seize the Libyan capital by military strongman Khalifa Haftar since April.
As in Syria, the Libyan conflict has become a battle for influence between regional players, with Turkey's bitterest rivals, Egypt and the United Arab Emirates, backing Haftar's Libyan National Army.
The issue returned to the spotlight after Turkish President Recep Tayyip Erdogan welcomed the head of the GNA, Prime Minister Fayez al-Sarraj, to Istanbul last month to sign military and maritime agreements.
"Turkey has found itself a natural ally of the GNA. They share the same opponents in different theatres," said Anas El Gomati, director of Tripoli-based think tank, Sadeq Institute, noting the "commercial and political" reasons behind Ankara's support.
"Sarraj has no real force of his own... He badly needs Turkish support to have any chance of counterbalancing Haftar," added Libya specialist Alison Pargeter, of Kings College London.
The maritime deal -- which divides much of the Eastern Mediterranean between Turkey and Libya -- is particularly important given the recent discovery of vast gas reserves that has triggered an exploration scramble between adjacent states and international oil companies.
Greece responded angrily to the Turkey-Libya deal, expelling the Libyan ambassador and urging the UN to condemn it. Turkey already faces European Union sanctions over ships searching for oil and gas off Cyprus, whose government in Nicosia is not recognised by Turkey.
Analysts say the agreement was a response to Turkey being frozen out by others in the region.
Earlier this year, energy ministers from Cyprus, Greece, Egypt, Israel, Jordan, Italy and the Palestinian territories agreed to create the "East Mediterranean Gas Forum" without Turkey.
"Turkey fears that it is being boxed in from its southern flank, faced with plans for a future gas pipeline to link Cypriot gas fields with European markets," said Ege Seckin, an analyst focusing on Turkey at IHS Markit.
"The maritime boundaries drawn under the deal cover an area that reaches from southwest Turkey to northeast Libya, cutting across the planned route for this pipeline."
Libya's GNA is the only international partner that supports Ankara's maritime borders.
"If Haftar won the civil war in Libya, Turkey would find itself with no other branch to hold on in the eastern Mediterranean," said Seckin.
- Military support -
To forestall that outcome, Erdogan said this week that he was ready to send troops if they were requested by Sarraj's government in Tripoli.
A UN report said last month several countries were already violating the arms embargo on Libya in place since the overthrow of its long-time dictator Moamer Kadhafi in 2011.
Jordan and the UAE regularly supply Haftar's forces, while Turkey supported the GNA, the report said. Turkish and Emirati drones were spotted in Libyan skies during clashes this summer.
Erdogan has said Turkey may hold patrols in the Mediterranean, which Secken said could include waters around the Greek island of Crete.
Another motivating factor, added Seckin, is that Turkey sees Haftar as "a Libyan copy" of Egyptian President Abdel Fattah al-Sisi.
Erdogan strongly backed Egypt's Muslim Brotherhood government that was overthrown by Sisi in 2013, and they have been bitter rivals since.
Haftar has previously ordered his forces to target Turkish companies and arrest Turkish nationals. Six Turkish sailors were briefly held by his forces over the summer.
Reports of Russian mercenaries supporting Haftar -- so far denied by Moscow -- have added a new element to the dangers for the GNA.
Erdogan has said that he does not wish the situation in Libya to "give birth to another Syria", where Ankara and Moscow are on opposing sides of the eight-year conflict despite joint efforts to end the war.