Four other servicemen were wounded in the incident when they came under fire in the southern town of Kismayo.
The US special operations forces were fighting alongside about 800 troops from the Somali National Security Forces and Kenyan Defence Forces when they were attacked late by mortars and small arms fire.
About 500 US troops are deployed in Somalia.
"We attacked a military base ... killed one US soldier, two Kenyan soldiers and nine Somali soldiers from Jubbaland state. We also injured four US soldiers," Abdiasis Abu Musab, al-Shabaab’s military operations spokesman, said.
The US military said in a statement one local soldier was also wounded in the attack.
The troops had been on a mission to clear al-Shabaab from contested areas as well as villages the militants controlled, "and establish a permanent combat outpost" to expand the reach of the Somali state," it added.
Sending his condolences on Twitter Mr Trump said: “My thoughts and prayers are with the families of our serviceman who was killed and his fellow servicemen who were wounded in Somalia. They are truly all HEROES.”
Kenyan military spokesman David Obonyo said its forces were not involved in any operations in Somalia.
Al-Shabaab is fighting to overthrow Somalia's central government and establish its own rule based on its interpretation of Islamic law.
After it wAS pushed out of Mogadishu in 2011, the group has lost control of most of Somalia's cities and towns, but it retains a strong presence in regions outside the capital.
Agencies contributed to this report
Join our new commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies