The Somali National Army said on Saturday that it had retained control of two bases, after attacks by Al Shabab extremists earlier in the day.
Both sides reported casualties.
The bases, about 100 kilometres south-west of the capital Mogadishu, were struck by two explosions, witnesses said.
A third explosion targeted a convoy of troops rushing to the bases from the capital after the attack, they said.
Hussein Nur, a military officer, said the army lost "several" soldiers in the attack on Bariire and Awdhigle bases.
The army sent in reinforcements from other stations, who killed an unspecified number of attackers in the ensuing fight, he told Reuters.
It was now in control of both bases and the surrounding areas, he said.
"We are pursuing the militants in the surrounding jungle," Mr Nur said.
Al Shabab claimed it launched a vehicle-borne suicide bomb attack on the Bariire base, while simultaneously attacking the nearby Awdhigle base with a car bomb and fighters, to prevent troops stationed there from reinforcing Bariire.
"We overran Bariire base, burnt three military vehicles and took two vehicles," said a spokesman from Al Shabab's propaganda unit.
A third vehicle-borne explosive device hit a convoy of reinforcement government troops coming from Mogadishu, he claimed.
The spokesman also said there had been casualties on both sides.
Al Shabab, which is linked to Al Qaeda, has waged years of attacks and levied tolls on trade in a campaign to introduce strict religious law.