The early-morning raid occurred in Busley, some 40 kilometers from Mogadishu, where Somali security forces have set up temporary bases for operations against Al-Shabaab dominated villages in the region, according to security sources.
Armed fighters from al Shabaab battled their way to the facility using suicide car bombs, a Somalia military officer told Reuters. He declined to be named because he was not authorized to speak to the media.
"Several suicide car bombs attacked the base after fierce fighting...al Shabaab briefly captured the base," the officer said.
"Then, government reinforcement fiercely battled and drove out al Shabaab."
Seven Somalia soldiers, including the commander of the base, and 10 al Shabaab fighters were killed in the fighting, he said.
Some residents in the area told Reuters al Shabaab also burned military vehicles and took others during the assault.
Al Shabaab issued a statement claiming responsibility for the attack. It said it had killed 57 government soldiers. The group frequently gives casualty figures that are higher than those of the government.
The claims could not be independently verified and the Somali government has made no official comment on the attack, AFP reported.
The assault comes after Al-Shabaab gunmen attacked a hotel near the presidential palace in Mogadishu on March 14, killing three people and demonstrating the group's continued ability to strike despite a major military offensive against the jihadists.
The al Qaeda-allied group has been fighting for nearly two decades, aiming to topple Somalia's central government and establish its own rule based on its strict interpretation of Islamic sharia law.
Some information in this report came from Reuters and AFP