At least 10 people, including soldiers and civilians, have been killed after armed group al-Shabab carried out a suicide attack at a police station in the city of Afgoye.
Captain Abdullahi Ali, a senior Somali military officer, told Associated Press news agency on Wednesday that troops have now fully secured the town and the fighters have fled.
The African Union's peacekeeping mission in Somalia, AMISOM, confirmed on Twitter that a car bomb had been used to target a police post but said Somali forces had held their position, waiting for reinforcements.
Tuesday's clashes started when a suicide bomber detonated an explosives-laden vehicle near a police station and an African Union base. Gunmen then stormed the area, attacking military bases in the strategic city about 30km northwest of the capital Mogadishu.
"We don't have the exact number of casualties so far but we have seen the dead bodies of more than 10 people, including civilians, who were killed in the attack," local police official Abdukadir Ahmed told AFP news agency.
Al-Shabab, which has been carrying out a series of deadly bombings throughout Somalia, claimed responsibility for the attack.
In a statement, the armed group said it had recaptured the town, which it evacuated in May 2012 after coming under attack from the Somali army and African Union peacekeepers.
Residents also told AP that troops had recaptured the town, with hundreds of soldiers patrolling the streets.
Earlier, Afgoye resident Amin Moalim said the town had been taken by surprise and "people are hiding in their houses and those who stayed outside have fled".
READ MORE: Al-Shabab fighters attack Somali army base
"I saw wounded civilians and Somali soldiers as well," he told AFP. "We don't know who is controlling the city so far because heavy exchange of gunfire is going on."
Al-Shabab has carried out numerous attacks in Somalia to try to topple the western-backed government.
Source: News Agencies