The assault on a base 50 km (30 miles) outside Mogadishu was part of the group's campaign to try to topple the Western-backed government and impose its own strict interpretation of Islam.
Al Shabaab hit army base, kill at least 10 soldiers
Al Shabaab spokesman Abdiasis Abu Musab said 30 soldiers had been killed in the raid that lasted several hours before his group's withdrew.
Recommended articles
"Heavy exchange of gunfire continued for hours," Major Ahmed Farah told Reuters from the nearby town of Afgooye. At least 12 al Shabaab fighters were killed, he added.
Al Shabaab spokesman Abdiasis Abu Musab said 30 soldiers had been killed in the raid that lasted several hours before his group's withdrew. He did not mention al Shabaab casualties.
The group often cites a higher death toll than officials.
On Sunday, the president's office said in a statement the government destroyed an al Shabaab base used to store military supplies in a region south of Mogadishu without resistance.
JOIN OUR PULSE COMMUNITY!
Eyewitness? Submit your stories now via social or:
Email: eyewitness@pulse.ng