CAIRO—The U.S. military said it pulled a small contingent of American forces from Libya as the country teetered on the brink of full-scale civil war, with fighting continuing around the capital Tripoli.

The evacuation is the latest turn in a troubled history of American military involvement in Libya, which has been in turmoil since the overthrow of Moammar Gadhafi in an armed uprising supported by North Atlantic Treaty Organization airstrikes in 2011. U.S. forces have also played a key role in uprooting Islamic State, which...