In what Western powers considered a strategic victory, government troops and African peacekeepers last month drove the al-Qaeda-allied al Shabaab rebels out of the capital Mogadishu, as the group suffered from internal divisions, a reported lack of combatants and funding shortages.
But the insurgents' latest assault shows they remain capable of launching major attacks for territorial gains at a time when aid groups are struggling to help more than 1 million Somalis struck by famine in southern and central Somalia.
Early on Friday the rebels entered Dhobley, near the Kenyan border, from three directions, attacking government troops and an allied militia known as the Raskamboni, a resident who fled the fighting said from Kenya.
"It was morning when al Shabaab attacked us from different directions ... I have seen 13 dead bodies mostly from the Raskamboni. We can say al Shabaab is now fully in the city, and the casualties may be more than that," officer Mohammed Wardhere told Reuters from the border.
A few hours later, residents said the Somali military regained control of the town.
"A more serious fight took place hours after government troops regrouped. However, al Shabaab is not far and fighting may restart at any time," resident Abdiqader Saciid said by telephone.
Al Shabaab said it lost six fighters and killed 40 government soldiers.