Military officials say 13 Somali soldiers have been killed by al-Shabab militants near the Afgoi district, northwest of the capital.
The group has been fighting a Western-backed central government in Somalia for more than 10 years to establish its own government based on a strict interpretation of Islamic law.
Commenting on the incident on Wednesday in a district 30 kilometers (19 miles) from Mogadishu, Major Mohammed Ali said, “We left the Afghan district and attacked al-Shabab in the fields outside Afghanistan.
“We killed four militants and pursued al-Shabab,” Ali said Wednesday. Most of the soldiers returned, and we left two dozen soldiers there. This evening al-Shabab attacked some of our soldiers and killed 13 of them.
Al Qaeda-linked militant groups have blamed the deadly attack on Somalia’s central government.
“We killed 24 soldiers and the rest fled,” said Abdus Abu Musab, the group’s military operations spokesman.
The Somali government and al-Shabab, with the support of the United Nations and the African Union, frequently report casualties after attacks.
The Somali militant group controls large parts of southern and central Somalia, regularly bombing military and civilian bases in hotels, squares and post offices.
Tens of thousands have been killed in fighting between armed groups and Somali government forces over the past 30 years.
In August, al-Shabab opened fire on a beachfront hotel in the capital, killing 10 civilians and a police officer.
That same month, four al-Shabab militants detained at Mogadishu Central Prison were killed in heavy gunfire with security forces who were somehow able to lay down their weapons inside the compound.
In August, seven people were killed when a car bomb exploded at a military base in Mogadishu, where members of the Somali National Army (SNA) were being held.