The U.S. military secretly deployed a small number of trainers and advisers to Somalia in October, the first time regular troops have been stationed in the war-ravaged country since 1993, when two helicopters were shot down and 18 Americans killed in the “Black Hawk Down” disaster.

A cell of U.S. military personnel has been in the Somali capital of Mogadishu to advise and coordinate operations with African troops fighting to wrest control of the country from the al-Shabab militia, an Islamist group whose leaders have professed loyalty to al-Qaeda, according to three U.S. military officials.

The previously undisclosed deployment — of fewer than two dozen troops — reverses two decades of U.S. policy that effectively prohibited military “boots on the ground” in Somalia. Even as Somali pirates and terrorists emerged as the top security threat in the region, successive presidential administrations and the Pentagon shied away from sending troops there for fear of a repeat of the Black Hawk Down debacle.

In recent years, the Obama administration has slowly and cautiously become more directly involved in Somalia.

Drones from a U.S. base in Djibouti — a neighboring Horn of Africa country — conduct surveillance missions and occasional airstrikes from Somalia’s skies. Elite Special Operations forces have also set foot on Somali territory on rare occasions to carry out counterterrorism raids and hostage rescues, but only in the shadows and for no more than a few hours at a time.

In January 2013, the United States officially recognized a new federal government of Somalia, reestablishing diplomatic relations for the first time since the country’s political structure collapsed in 1991. The State Department has not reopened an embassy in Mogadishu, but U.S. diplomats often make brief trips to the capital.

The CIA has quietly operated a base in Somalia for years and finances Somali security forces, but largely keeps its activities there under wraps.

U.S. intentions to become more involved militarily became apparent last summer, when Gen. David Rodriguez, the commander of U.S. forces in Africa, visited Mogadishu.

In October, Amanda Dory, the Pentagon’s top policy official for Africa, told Congress that the military would “increase our presence in Mogadishu in tandem with the State Department.”

Although Dory did not provide details, the U.S. Africa Command around the same time deployed a handful of advisers to Mogadishu to establish a coordination cell with Somali security forces and a regional coalition of African troops, according to the three U.S. military officials who spoke on condition of anonymity because the mission had not been publicly announced.

In a statement late Friday, Army Col. Thomas Davis, a spokesman for the Africa Command, confirmed the deployment. He said a military coordination cell was established in Somalia in October “and is now fully operational.”

October marked the 20th anniversary of the Black Hawk Down battle between a task force of U.S. Army Rangers and Delta Force commandos and fighters loyal to Somali warlord Mohamed Farah Aideed.

U.S. military forces were in Somalia at the time to support a United Nations humanitarian operation. But the heavy losses — and haunting images of dead Americans being dragged through the streets — prompted a quick U.S. withdrawal and for years discouraged Washington from intervening in other conflicts.

Since 2007, the U.S. government has spent more than $500 million to train and equip an African Union force of more than 18,000 soldiers that has sought to bring order to Somalia and strengthen the weak Somali national government. Most of the soldiers come from Uganda and Burundi and receive training in camps outside Somalia from U.S. contractors and uniformed military advisers.

The United States has also spent more than $170 million to build up the nascent Somali national army, although that force is relatively weak and unreliable.

The African Union forces control most of Mogadishu and are making gradual headway in securing other territory. Ethi­o­pia and Kenya have also sent troops into Somalia and control regions near their borders. Despite all the interventions, however, al-Shabab remains a potent force and in control of large parts of the country.

Al-Shabab, which means “the youth” in Arabic, has been leading an insurgency for several years against Somalia’s Western-backed leaders. The militia imposes strict Islamic law over the cities and villages it controls. Its leaders announced a merger with al-Qaeda two years ago, although U.S. analysts differ on how much of a direct threat it poses to the United States.

The militia has organized several terrorist plots in other countries in East Africa, including a four-day armed siege of an upscale shopping center in Nairobi in September that killed dozens of people.

Somalia has been plagued by famine and civil strife for more than two decades.

For many years, Mogadishu was known as one of the most dangerous cities in the world, a symbol of the lawlessness that gripped the entire country. Conditions are slowly improving, and the State Department has said it wants to reopen an embassy in the capital, but is waiting for terrorist threats to subside further.

“We eventually need to establish a permanent U.S. diplomatic presence in Somalia,” Linda Thomas-Greenfield, the State Department’s deputy assistant secretary for African affairs, told a Senate panel in October. “Ultimately, it is the security conditions in Somalia that will dictate when we can establish a more permanent presence and we recognize that the time is not right to do this.”