Somali Islamists seized control of a southern town on Sunday, killing nine government troops.
Government forces have been struggling to maintain control
The rebels, armed with rocket launchers and machine guns, voluntarily retreated after three hours, said a police officer in Dinsoor, Mohamed Ahmadey.
He said the town had been under "no-one's control" since the incident, in which eight soldiers were wounded.
For more than a year, government forces backed by Ethiopian troops have struggled to assert control in Somalia.
The capital, Mogadishu, has often been the focus of the fighting between the government forces and the Islamists they ousted from power.
But the incident on Sunday shows the Islamists are increasing their attacks outside Mogadishu, says the BBC's Mohamed Olad Hassan in Somalia.
A spokesman for the Islamists' Shahab youth wing, Sheikh Muktar Ali Robow, told local radio that he was leading the rebel unit that seized the town.
"Our troops moved into the town to dismiss bandits under the cloak of Somalia's honourable army. We defeated those, burned three of their military vehicles and seized two others, he said.
We spoke to the town's residents in public and told them that we were not in a position to harm any one and ordered them to maintain their ordinary activities, and later withdrew from the town, he said.
Residents of the town confirmed the incident, but there has been no comment yet from any senior government official.