Al Shabab fighters stormed the Galcad base early on Friday, exploding car bombs and firing their weapons, Captain Issa Abdullahi said.
The attack was eventually repelled, an officer at the base in the central Somali town of Galcad told Reuters.
He said the dead included the base's deputy commander, who was part of a U.S.-trained unit stationed there.
Somalia's information ministry said in a statement that in addition to al Shabab killing seven soldiers, their soldiers had killed 100 of the group's fighters and destroyed five gun-mounted pick-up vehicles known as technicals.
In a statement al Shabaab said it had "miraculously overrun the U.S.-trained forces" in the town and killed scores of soldiers.
The government and al Shabab often give different casualty numbers from the same attack.
The base is run by Danab, a unit of commandos who have participated in the offensive against the militants.
Government forces just this week seized Galcad and the port town of Harardhere in Somalia's Galmudug region from al Shabab control, a major success for the ongoing government offensive.
Galcad resident Abdullahi Nur told Reuters he heard huge blasts at the base, followed by heavy fighting and air strikes early on Friday.
"We have been celebrating the liberation of the town but it is now covered with smoke. May God save us," he said.
The attack underscores the formidable threat al Shabab poses for Somalia's military, even after a government offensive launched last year scored significant success against the al Qaeda-allied militants.