"Violent elements attacked government forces in northern Mogadishu, sparking heavy fighting. They were defeated and several of their fighters were killed," government security officer Mohamed Abdirahman told AFP.
"Two of our soldiers were also killed as well as three civilians who were caught in the crossfire," he added.
Insurgents have been harassing government forces in northeastern districts lately to seize positions from which they can target bases of the African Union mission in Somalia (AMISOM) and disrupt their supplies by striking the seaport.
Rebels from the Al Qaeda-inspired Shebab movement and the Hezb al-Islam group in May 2009 launched a major offensive which President Sharif Sheikh Ahmed's forces and his AMISOM protectors have been unable to repel.
Ali Muse, the head of Mogadishu's ambulance services, also told AFP that three other civilians, including two from the same family, were killed when an artillery shell smashed into their home in Halimoheyte district.
In a separate incident in the southern Labadhagah neighbourhood, six Hezb al-Islam militants, including one of the group's top commanders, were mowed down when gunmen in a minivan intercepted their vehicle, witnesses said.
Minutes later, two Shebab fighters were killed outside a nearby mosque where the group's top leaders usually preach, in an apparent retaliation for the earlier executions.
"I was sitting at a teashop close to the place where the six were gunned down. I saw the minivan stop the car. They sprayed gunfire on them, all of them died and their bodies were riddled with bullets," Abdullahi Farah said.
"It was horrible to see all the dead in a pool of blood. The attackers left the scene but minutes later two Shebab fighters were shot dead near Nasruddin mosque," said Nur Abdiweli, another witness.
"I think it was an act of retaliation," he said.
The Shebab, who control most of the country, and the smaller Hezb al-Islam are theoretically allied in their push to topple Sharif but have often been at odds, with their differences chronically erupting into bloodshed.
Hundreds of Shebab supporters held a demonstration Monday in Suqaholaha, on the outskirts of Mogadishu, to demand the departure of African Union troops, blaming them for civilian deaths.
"AMISOM killed my dad" read one placard at the protest, which was organised by the insurgent group. Several fully veiled women could also be seen brandishing assault rifles.
Heads of state from the regional body IGAD (Inter-Governmental Authority on Development) held an extraordinary meeting in Addis Ababa Monday and pledged to send 2,000 more troops to beef up AMISOM.
Since it was first deployed in 2007, the African force never reached its intended strength of 8,100 with only Uganda and Burundi contributing troops.
IGAD said it hoped to deploy the extra troops by September but did not specify which of its six members states would provide soldiers.