The Trump administration in the United States has ordered the withdrawal of nearly all US troops from Somalia by 15 January, the Pentagon said.
US has about 700 troops in the country helping local forces battle al-Shabab and Islamic State militants.
US officials said some of the troops would move to neighbouring countries, allowing for cross-border operations.
In recent months President Trump has issued similar orders to reduce US forces in Iraq and Afghanistan.
He has long called for US troops to come home and has criticised US military interventions for being costly and ineffective.
The withdrawal order comes days before Mr Trump leaves office.
The Pentagon in a statement said that the order to “reposition the majority of personnel and assets out of Somalia by early 2021” did not signify a change in US policy.
“We will continue to degrade violent extremist organisations that could threaten our homeland while ensuring we maintain our strategic advantage in great power competition,” it said.
Somalia has suffered decades of political instability but in recent years a peacekeeping force from the African Union along with US troops have reclaimed control of Mogadishu and other areas from al-Shabab – an al-Qaeda affiliate.
The group has fought for more than 10 years to impose a regime based on a strict version of Sharia law, and often attacks civilian and military targets, carrying out bombings and assassinations in the capital.