The attack on Gofgadud base in the Bay region marks the latest setback for Somalia's army, which is expected to take over responsibility for the country's security from an African Union force next year.
Officials in Somalia say al Shabab militants killed three soldiers during an attack on a military base in the southwest on Monday.
The assault on the Gofgadud base in the Bay region by the al Qaeda-affiliated group marks the latest setback for Somalia's army, which is expected to take over responsibility for the country's security from an African Union force next year.
Colonel Ahmed Yusuf, a Somali military officer, said Somali troops made a brief tactical withdrawal amid heavy artillery shelling before regaining control of the base.
He said six al Shabab militants were killed in the army’s counter-attack that forced the extremists to withdraw.
Al Shabab claimed responsibility for the attack, asserting that it killed or wounded more than 30 soldiers.
Years of conflict and al Shabab attacks, along with famine, shattered Somalia, which is home to more than 12 million people.
The Horn of Africa nation has been trying to rebuild since establishing its first functioning transitional government in 2012.
Al Shabab was pushed out of the capital, Mogadishu, and other major cities several years ago but still carries out suicide attacks across Somalia.
With a federal government established, pressure is growing on Somalia’s military to assume full responsibility for the country’s security.