Washington (AFP) - A group of US special operations troops who had traveled to Libya to "foster relationships" was kicked out of the conflict-torn country soon after they arrived, the Pentagon said Thursday.

A Facebook page belonging to the Libyan air force posted photographs of the men, who were dressed in rugged civilian clothing, including plaid shirts, and were carrying assault rifles.

A US defense official confirmed that the men in the photo were indeed US troops in Libya on Monday.

Speaking on condition of anonymity, the official said the troops were in Libya "with the concurrence of Libyan officials."

"US military personnel traveled to Libya on 14 December to foster relationships and enhance communication with their counterparts in the Libyan National Army," the official said.

"While in Libya, members of a local militia demanded that the US personnel depart. In an effort to avoid conflict, they did leave, without incident."

Since the oil-rich North African nation descended into chaos after the ouster and killing of long-time leader Moamer Kadhafi in 2011, authorities have struggled to maintain order in a country splintered by tribal loyalties and former militias vying for power.

Taking advantage of the chaos, the Islamic State group has gained a foothold in Libya, which has also become a hub for trafficking of migrants towards Europe.