The fighting broke out when newly trained government forces backed by the soldiers of the African Union mission in Somalia (AMISOM) apparently launched a major offensive to recapture key Mogadishu neighborhoods.

The internationally backed government had lost ground last month when insurgents, mainly from Al-Qaeda-inspired Al-Shabaab movement, punched through a strategic frontline and closed in on the presidential compound.

"The Somali government forces advanced on the terrorists' strongholds this morning," Col. Ahmed Ibrahim, a government security official, told AFP.

"They took control of several neighborhoods which had been held by the rebels and the fighting is still going on. There are several bodies strewn across the streets," he added.

Medical sources counted at least 21 civilian deaths after the first few hours of fighting but expected the toll to rise, with no immediate information on combatant casualties and several areas impossible to access independently.

Meanwhile, security forces from Somalia's semi-autonomous Puntland region stormed a hijacked cargo vessel early on Thursday and outgunned the pirates holding it after they fatally shot the ship's Pakistani captain, authorities said.

Authorities decided to try and free the Panama-flagged ship by force after pirates refused pleas to surrender and instead killed the captain, said Said Mohamed Raage, who is the minister of marine transport and ports in the region.

“We can't afford letting pirates capture Somali-charted ships. If we don't act so decisively they will continue hijacking all Somali-bound cargo ships,” Raage told The Associated Press.