File Photo: Smoke billows from the scene of a car bomb explosion in the Kilometre 4 area of Mogadishu, Somalia January 31, 2021.. REUTER
The attack came as the troubled country was in the grip of an escalating political crisis pitting the president against the prime minister.
The attackers, armed with machine guns, raided the town of Balcad, about 30 kilometres (18 miles) north of Mogadishu, police and witnesses said.
"The terrorists attacked Balcad early this morning targeting government security checkpoints," police officer Abdullahi Mohamed told AFP by phone.
"The situation returned to normal now and the government forces are in full control."
Witnesses said the Al-Shabaab fighters managed to enter some parts of the town, which lies along a road linking Mogadishu to rest of the country, before they were repelled.
President Mohamed Abdullahi Mohamed and Prime Minister Mohamed Hussein Roble are locked in a festering feud over long-delayed elections in the Horn of Africa nation.
The president, better known as Farmajo, this week announced he was suspending the premier, who in turn accused him of an "attempted coup".
Relations between the pair have long been frosty, with the latest developments raising fresh fears among international partners that the government could be distracted from its fight to quash the jihadist insurgency.
Al-Shabaab has been waging a violent campaign against the country's fragile government since 2007 but was driven out of Mogadishu in 2011 after an offensive by an African Union force.
But the Al-Qaeda-linked insurgents retain control of vast rural areas of Somalia, from which they frequently launch deadly attacks in the capital and elsewhere against civilian, military and government targets.
The extremists last month claimed a deadly car bombing in the capital that killed eight people and injured a number of students.
The militants also claimed two attacks in September that together killed 17 people.