Emergency officials in Mogadishu said that 20 people, mostly civilians, died when the African union peacekeeping forces backing the Somali government troops retaliated to insurgent mortars in the north of the city.
Local ambulance services said that almost 40 people were injured as the shells showered over residential areas in the insurgent-held north of the Somali capital Mogadishu.
Witnesses said that shells also hit a number of other areas in the south of the restive coastal capital.
The duel came as a roadside bomb explosion targeting Somali army chief earlier killed at least one of the army commander's bodyguard and wounded five others but the newly-appointed army head, Mohamed Gele Kahiye, narrowly escaped as he was not in his vehicle at the time.
Both Somali government and hard-line Islamist insurgents have been preparing for a possible major confrontation over the control of Mogadishu, the Somalia capital which is partly controlled by the two sides.
The Somali government has lately been restructuring its security forces many of whom have recently received training aboard while top security officials were changed as the Somali government says it is preparing for a major assault to retake the capital city.
Islamist groups have also been making their own preparations and paraded hundreds of newly trained fighters and armory in their bases in Mogadishu.
The Islamist rebels, who control much of the capital as well as all of south and center of Somalia, have also made huge trenches in the middle of major streets in Mogadishu between areas under the insurgents' control and that of the government.
War of words have been escalating between the two sides in recent days causing the few remaining families in frontline areas in Mogadishu to begin fleeing their homes in fear they may get trapped when fighting breaks.
Editor: Mu Xuequan