The order changes the mission American troops had to assist the local Somali military in its fight against al-Shabab, an al-Qaida affiliated group, but will allow counterterrorism strikes against the group to continue as needed.
"The President of the United States has ordered the Department of Defense and the United States Africa Command to reposition the majority of personnel and assets out of Somalia by early 2021," said a Defense Department statement issued late Friday
"The U.S. is not withdrawing or disengaging from Africa," the statement stressed. "We remain committed to our African partners and enduring support through a whole-of-government approach."
The U.S. has about 700 military personnel in Somalia, most of whom have have been assisting the Somali military in its fight against al-Shabab, a terrorist group affiliated with al-Qaida.
For weeks there has been speculation that the U.S. military troop presence there might be reduced significantly or fully withdrawn. That would have been in line with President Donald Trump's recent decisions to downsize the number of troops in Iraq and Afghanistan to 2,500.
A defense official told ABC News that acting Defense Secretary Chris Miller made a decision on a troop reduction this week and felt it was important to have conversations with members of Congress, the relevant combatant commands and partner nations prior to making a decision.
Miller visited Somalia's capital of Mogadishu last week, becoming the first defense secretary to ever visit Somalia. The stop was part of a trip visiting American troops in the Middle East and the Horn of Africa.
Under the order, the majority of U.S. troops will "reposition" out of Somalia -- either out of the region or to neighboring countries -- "to allow cross-border operations by both U.S. and partner forces to maintain pressure against violent extremist organizations operating in Somalia."
"The U.S. will retain the capability to conduct targeted counterterrorism operations in Somalia, and collect early warnings and indicators regarding threats to the homeland," said the statement.
The U.S. operates counterterrorism operations against al-Shabab in Somalia from bases in neighboring Djibouti and Kenya. It is unclear if any of the troops leaving Somalia will be moved to the base at Manda Bay, Kenya, which suffered a large assault from al-Shabab fighters that killed three Americans.
It is not only U.S. military personnel that are at risk in Somalia. Early last week a CIA paramilitary officer was killed in Somalia, according to an official familiar with the operation. On Thursday, Gen. Mark Milley, the chairman of the Joint Chiefs of Staff, disclosed that the deceased CIA officer had previously served in the military as a Navy SEAL.
Despite the reassurance that a counterterrorism mission would continue, Friday's announcement was met with concern by some security analysts.
Eric Oehlerich, an ABC News contributor and former Navy SEAL with experience in the region, said the threat of al-Qaida and al-Shabab has been reduced thanks to cooperation with African Union countries, but at a price.
"This has come at the cost of American lives and investment," said Oehlerich. "Reducing our resources in this winnable conflict is a detriment to our African partners in East Africa and will only embolden al-Shabab extremist behavior in the region."
"Left unchecked we could see what happened at the Westgate Mall in Kenya in 2015 when 67 civilians were killed by al-Shabab, an affiliate of al-Qaida, happen again," said Mick Mulroy, an ABC News contributor and former deputy assistant secretary of Defense and a retired CIA officer and U.S. Marine who served in Somalia.
"We have reduced their capacity to carry out external attacks, not their willingness," said Mulroy.
"We can always adjust the level of forces based on the current threat as assessed by our intelligence services, but withdrawing all of our forces is a mistake," he added. "In the future we may have to fight our way back in, just to get to the place we are right now."