A US serviceman was killed and two were wounded in a clash with al Shabaab militants in Somalia, the US military said on Friday, in what appeared to be the first American casualties in the country since the 1993 "Black Hawk Down" disaster.

The White House has granted the US military broader authority to carry out strikes in Somalia against al Qaeda-linked al Shabaab, the latest sign President Donald Trump is increasing US military engagement in the region.

US Africa Command said the serviceman was killed by small arms fire on Thursday while US forces were advising and assisting a Somali National Army operation in Barii about 40 miles (60 km) west of Mogadishu.

"Although US forces are not engaged in direct action (in Somalia), advise and assist missions are inherently dangerous," said Robyn Mack, a spokeswoman at the US military’s Africa Command.

US Africa Command said US personnel were working alongside members of the Somali military.

"US forces are assisting partner forces to counter al-Shabaab in Somalia to degrade the al Qaeda affiliate's ability to recruit, train and plot external terror attacks throughout the region and in America," it said in a statement.

In the "Black Hawk Down" incident, 18 US soldiers were killed after Somali militia shot down two US helicopters in the capital of Mogadishu.

In Friday's incident, US troops were hunting an al Shabaab commander near the Shabelle river alongside Somali special forces, a Mogadishu-based security source told Reuters. There were no Somali casualties.

A spokesman for al Shabaab, which wants to overthrow the weak Western-backed Somali government and impose its own strict brand of Islamic law, said US troops had attacked one of their bases.

"Last night at 1 a.m. US forces attacked us in Darusalam village, in lower Shabelle region. After fighting, the US forces ran away," said Sheikh Abdiasis Abu Musab, al Shabaab’s military operation spokesman.

"They left ammunition and weapons on the scene and blood stains. First they had a helicopter which landed some kilometers away from our base, to which they walked. We inflicted heavy casualties - some forces died and others were wounded but we do not have the exact figure."

Residents of Darusalam village said the gunfire lasted for around 10 minutes. "Last night, helicopters hovered over us and we were scared. Then late at night, there was fighting," resident Mohamed Hassan told Reuters.

Somalia has been shattered by civil war that began when clan-based warlords overthrew a dictator in 1991 and then turned on each other. African Union peacekeeping forces have been in Somalia since 2007 as part of a reconstruction drive.