Residents of Runirgood said they had seen dead bodies of both al Shabaab and government soldiers in the town
The Islamist group, which wants to topple Somalia's Western-backed government, said it had killed 32 soldiers in the assault. It was not possible to verify independently the death toll. Al Shabaab has inflated casualty figures in the past.
Captain Nur Ali said the attack had taken place early on Sunday morning in the town of Runirgood, about 180 km to the north east of Mogadishu.
"Al Shabaab used a suicide car bomb to penetrate a military base. It exploded and then fierce fighting followed. At least 15 soldiers died," Major Abdullahi Omar, a second army officer, told Reuters from the region by phone.
"The soldiers (at the base) were few and there were no AMISOM or other military nearby for reinforcement. We killed more than 10 militants in fighting on Saturday and Sunday," Omar added. AMISOM is the African Union peacekeeping mission.
Residents of Runirgood said they had seen dead bodies of both al Shabaab and government soldiers in the town.
Abdiasis Abu Musab, al Shabaab's spokesman for military operations, said its fighters had killed 32 soldiers and captured three vehicles.
"It was a fierce battle and thank Allah, we recaptured the town," he told Reuters.
Somalia's government is battling to rebuild the Horn of Africa nation after more than two decades of conflict. Al Shabaab ruled large parts of Somalia until 2011, when it was driven out of Mogadishu by African Union and Somali troops.
It still controls some rural areas, however, and carries out frequent attacks in the capital and other areas.
Last week it attacked a Somali government military base and killed five soldiers near the northwestern town of Baidoa.