Turkey's parliament has approved military deployment to Libya aimed at shoring up the UN-backed government in Tripoli, sparking a blunt warning from US President Donald Trump against any "foreign interference" in the war torn country.

The beleaguered Tripoli government has been under sustained attack since April by military strongman General Khalifa Haftar, who is backed by Turkey's regional rivals - Saudi Arabia, Egypt and the United Arab Emirates.

In response to the prospect that Ankara might intervene, President Trump had told his Turkish counterpart Recep Tayyip Erdogan in a call "that foreign interference is complicating the situation in Libya," White House spokesman Hogan Gidley said in a statement.

Egypt also strongly condemned the Turkish vote, saying it amounted to a "flagrant violation of international law and Security Council resolutions on Libya".

President Erdogan is due to receive Russian President Vladimir Putin next Wednesday to inaugurate a new gas pipeline and Libya is expected to be a key topic of discussion.

Mr Erdogan has repeatedly accused Russia of sending private mercenaries to support Haftar's forces, though this has been denied by Moscow.

At the same time, Turkey and Russia have managed to work closely on the Syrian conflict despite supporting opposing sides, and are expected to seek a similar balancing act with regards to Libya.

Erdogan's office confirmed last Friday that a request for military support had been received from the internationally recognised Tripoli-based Government of National Accord (GNA).

No details have been given on the scale of the potential deployment, with officials saying that the date has also yet to be set.

Turkish parliament has voted to send troops to Libya

"We are ready. Our armed forces and our defence ministry are ready," Turkey's Vice-President Fuat Oktay said, adding that parliamentary approval would be valid for a year.

He described the parliament motion as a "political signal" aimed at deterring Haftar.

"After it passes, if the other side changes its attitude and says, 'OK, we are withdrawing, we are abandoning our offensive,' then what should we go there for?" 

The bill passed easily by 325 votes to 184.

"The Libyan motion is important for the protection of the interests of our country and for the peace and stability of the region," Foreign Minister Mevlut Cavusoglu tweeted after the vote.

Troops loyal to the internationally-recognised Tripoli government have been under attack from Haftar's fighters since April

Russia connection

A UN report in November said several countries were violating the arms embargo on Libya in place since the overthrow of long-time dictator Muammar Gaddafi in 2011.

Jordan and the UAE regularly supply Haftar's forces, it said, while Turkey supports the GNA. Turkish and Emirati drones were spotted in Libyan skies during clashes over the summer.

"We're supporting the internationally recognised legitimate government in Libya. Outside powers must stop supporting illegitimate groups against the Libyan government," Erdogan's communications director Fahrettin Altun tweeted last week.

Turkey has used its alliance with the Tripoli government to advance other interests.

It signed a military cooperation agreement with the GNA during a visit by its leader, Fayez al-Sarraj, to Istanbul in November.

But they also signed a maritime jurisdiction agreement giving Turkey rights to large swathes of the Mediterranean where gas reserves have recently been discovered.

Libya is expected to be on the agenda as presidents Erdogan and Putin meet next week 

The agreement drew international criticism, particularly from Greece which says it ignores its own claims to the area.

Analysts say Ankara was responding to being frozen out of regional energy deals, notably the "East Mediterranean Gas Forum", formed this year by Cyprus, Greece, Egypt, Israel, Jordan, Italy and the Palestinian territories.

Turkey's fierce rivalry with the military government in Egypt is seen as another motivating factor behind the planned deployment.

Mr Erdogan strongly backed Egypt's Muslim Brotherhood government that was violently overthrown by Egyptian President Abdel Fattah al-Sisi in 2013.

Haftar has previously ordered his forces to target Turkish companies and arrest Turkish nationals. Six Turkish sailors were briefly held by his forces during the summer.