The attack occurred in Afgoye district, located about 30 kilometers northwest of Mogadishu, on Sunday, according to police.
The government has deployed forces to Afgoye to ensure security in the region ahead of a presidential visit, Presstv Reported.
A Somali police officer told Reuters that the security forces opened fire at a hurtling car that blew up in Afgoye. “So far we know three soldiers died," Captain Nur Ali said.
Al-Shabab, however, has given a different account of the attack, saying 11 Somali soldiers have been killed.
In another incident, Somali forces killed two militants in a gunfight at a checkpoint in Mogadishu early Sunday, police said.
"Somalia's military killed two armed militants at Benadir checkpoint. Two soldiers were slightly injured in the exchange of fire," Major Mohamed Abdullahi, a police officer, told Reuters.
Despite being ousted from large parts of the south and central Somalia, al-Shabab continues deadly attacks across the country, which has been plagued by war and poverty for decades.
The terrorist group aims to topple the Western-backed government in Mogadishu and drive out African Union peacekeeping troops. It has been engaged in militancy since 2006.