Libya militia chases away US troops
US forces flown to Libya to support government troops had to leave after landing because of demands from a local militia group, US officials say.
It follows reports that 20 US special forces troops, equipped with advanced weaponry, landed on Monday at an airbase in western Libya.
The troops chose to leave "in an effort to avoid conflict", a US Africa Command (Africom) spokesman told the BBC.
Libya has been in chaos since the 2011 overthrow of Muammar Gaddafi.
The US forces had travelled to Libya in order to "foster relationships and enhance communication with their counterparts in the Libyan National Army", Africom spokesman Anthony Falvo told the BBC.
The soldiers left without incident, he added.
Analysis: Rana Jawad - BBC North Africa correspondent
It is undoubtedly an embarrassing revelation for the Americans.
The timing of the incident, so close to the long-awaited deal signed by Libya's rival parliaments on Thursday, has fuelled speculation among Libyans over what they see as the ulterior motives of the US and other Western nations.
There has been increasing suspicion that foreign troops are looking to establish their presence on the ground in Libya, especially with the so-called Islamic State grabbing more territory in recent months.
Reactions on social media ranged from accusations that the US was promoting one side of the conflict, to questions over the West's long-term military aims in Libya.
Western nations have repeatedly spoken of their intent to support Libyan armed forces to help secure the country and combat extremism.
However, if nothing else, the incident chiefly serves as a reminder of the challenges foreign military forces will face trying to operate in a country with no central security structure.
Mr Falvo did not elaborate further on why the troops' landing at al-Wattiya airbase had seemingly not been cleared with the relevant Libyan groups on the ground.
The airbase is not controlled directly by the Libyan army, but by a militia affiliated to it, which may explain the apparent breakdown in communication.
Unnamed Pentagon officials told national media that US forces had been "in and out of Libya" for some time, operating in an advisory, but not a combat role.
Photos of the secret mission were published on the official Facebook page of the Libyan Air Force, saying the troops had landed "without prior coordination".
It described the forces arriving "in combat readiness wearing bullet proof jackets" carrying night-vision goggles, GPS devices and assault rifles.
Libya's rival power bases (as of August 2015)
Libya has two rival governments, one based in the main city, Tripoli, and the other about 1,000km (620 miles) away in the port city of Tobruk.
Representatives of the two groups signed a deal in Morocco on Thursday, agreeing to form a national unity government, however their respective leaders voiced their reservations.