The attack came with the troubled country in the grip of an escalating political crisis pitting the president against the prime minister.
The attackers, armed with machine guns and RPG rocket-launchers, raided the town of Balcad, about 30 kilometres (18 miles) north of Mogadishu, police and witnesses said.
Four people, including two members of the security forces, were killed and eight others wounded, police officer Abdullahi Mohamed told AFP by phone.
The militants targeted government security checkpoints in the early morning raid "to terrorise the public", said Mohamed.
"The situation returned to normal now and the government forces are in full control," he added.
Witnesses said the ‘Al-Qaeda’ linked terrorists managed to enter some parts of the town, which lies along a road north of the capital linking Mogadishu to rest of the country, before they were repelled.
“Al-Shabaab” issued a statement claiming responsibility for the attack.