WASHINGTON — A medical evacuation helicopter reached five United States soldiers in Somalia on Friday roughly 20 minutes after they radioed that they were being shelled by Islamist militants, according to a military spokesman, a prompt response that underlines the disparity in American military resources spread across Africa.

One of the soldiers, Staff Sgt. Alexander W. Conrad, 26, of Chandler, Ariz., who was identified by the Pentagon on Saturday, died from his injuries shortly after he arrived at an American base in Kismayo, a town about 225 miles southwest of Mogadishu. The four other Americans were wounded in the attack by the militant group the Shabab.

The response to the firefight stood in stark contrast to the one after a bloody ambush in October on the Niger-Mali border in West Africa, when it took more than four hours to evacuate the wounded.

American troops have found themselves fighting militants affiliated with the Islamic State and Al Qaeda in several countries on the African continent.

The roughly 500 American troops in Somalia — stationed at a small constellation of bases throughout the East African nation — have been training and fighting alongside local troops there for more than a decade. They are now buttressed by invigorated airstrike authorities under the Trump administration.

Until recently, Special Operations troops in Somalia had been fighting a noticeably different war from their counterparts in West Africa, one constrained by a smaller geography and the longtime presence of extremist groups.

For any large operation like the one in Somalia on Friday, Special Operations troops routinely pre-stage medical evacuation helicopters and have armed air support.

By contrast, in the October ambush in Niger, which was led by more than 50 militants from the group known as the Islamic State in the Greater Sahara, the troops relied on contracted medical evacuation that is not as capable as the military’s. The only armed air support arrived by way of French fighter jets, more than an hour after the gun battle started.

The Americans’ vehicles were lightly armored pickup trucks and a sport utility vehicle. Four American soldiers died in the ambush.

During a seven-month investigation into the attack, led by officials from the Pentagon’s Africa Command, the Special Operations general in charge of American commandos in Africa issued a series of orders that roughly mirrored the actions in Somalia, putting in place stringent guidelines to ensure that those on the ground had the proper support before leaving on a mission.

The lower-level commands in Somalia and Niger, however, are different. In West Africa, Special Operations forces are overseen by Army Special Forces, while the Naval Special Warfare Command, often known as the Navy SEALs, leads operations in Somalia.

The attack on Friday came toward the end of a dayslong operation in which a team of Green Berets from the Thirrd Special Forces Group — the same unit that fought in the ambush in Niger — worked to clear several villages from Shabab control alongside 800 local troops from Somalia and Kenya. The American team, which numbered about 25, including civil affairs and intelligence personnel, had also helped with the construction of a combat outpost.

According to Maj. Casey Osborne, a spokesman for the Africa Command’s Special Operations branch in Germany, the enemy attack was quick, giving the armed reconnaissance aircraft overhead little time to find the militants firing at the Americans. According to one military official familiar with the attack, the Special Forces soldiers had less than a month left on their deployment.

The Shabab said in a post translated by the SITE Intelligence Group, which monitors online extremist message boards, that its fighters had attacked a joint American-Somali base near Kismayo, mounting what it called a “fierce attack.”

Over the past year, the Pentagon has shown renewed concerns about the Shabab, which was responsible for one of the deadliest terrorist attacks on African soil when it struck a popular shopping mall in 2013 in Nairobi, Kenya, killing at least 67 people.

American military officials worry that the group is growing once more, even after losing much of its territory in Somalia in recent years and being targeted by American drone strikes.

Major Osbourne provided a timeline of how the firefight played out.

At 2:42 p.m., the Green Berets reported that they were under attack, and five minutes later an American HH-60G Black Hawk helicopter left Kismayo to evacuate the wounded.

The aircraft picked up three wounded American team members and one wounded African soldier, leaving the landing zone near the attack at 3:05 p.m. The helicopter returned at 3:18 p.m. to Kismayo, where the wounded were treated. Sergeant Conrad died soon after.

The Black Hawk flew back to the battlefield at 4:52 p.m., retrieving another wounded American — one who was most likely in a more stable condition than his previously evacuated teammates — and arrived back at Kismayo at 5:21 p.m. At 7:22 p.m., an American C-130 transport plane left Kismayo with three wounded soldiers and the remains of Sergeant Conrad. It landed in Nairobi at 9:45 p.m., and the wounded were treated at a civilian hospital.

“Our strategy in East Africa is to build partner capacity to ensure that violent extremist organizations, who wish harm in the region, wish harm on the European continent, and ultimately wish to harm the United States, are contained,” Gen. Thomas D. Waldhauser, the head of the Africa Command, said in a statement on Saturday.

Sergeant Conrad deployed twice to Afghanistan, in 2012-13 and again in 2014, before completing French language training and being assigned to the Third Special Forces Group at Fort Bragg, N.C., as a human intelligence officer, someone who is trained to interact closely with local populations to learn information about militant groups. Much of the Third Group’s work is in French-speaking West Africa.

His death was the second American combat loss in Somalia in the past 13 months. Last May, a member of the Navy SEALs, Senior Chief Petty Officer Kyle Milliken, was killed and two other American troops were wounded in a raid.

A version of this article appears in print on , on Page A5 of the New York edition with the headline: Rapid Response in Somalia Firefight Shows Disparity in U.S. Resources. Order Reprints | Today’s Paper | Subscribe