Thousands of people have fled their homes in search of safety from the continuing fighting.
Sheikh Mohamed Ibrahim Bilal, a senior al-Shabaab official, said of the violence: "We killed an uncountable number of government fighters and moderate Islamists. Their dead bodies lie in the streets."
Mohamed Sheikh Nor, a journalist in Mogadishu speaking to Al Jazeera, described the recent violence as the worst since Ethiopian troops withdrew from Somalia in January.
Al-Shabaab and its allied groups were trying to take over government positions, he said.
"Omar Hashi, the security minister, said government positions were attacked by anti-peace elements including foreign fighters, some of them members of al-Qaeda.
"He said government will try all it can to defend itself."
Armed groups in Mogadishu have in recent days intensified attacks against government targets.
Sharif Ahmed, the former leader of the Islamic Courts Union, was sworn in as president in January and has pledged to do "everything imaginable" to stabilise Somalia.
He has been trying to broker peace with warring groups and gain legitimacy, but his administration wields little control outside Mogadishu and needs support from African Union peacekeepers.
Fighters opposed to the government see the 4,350 AU peacekeepers as "foreign invaders" and an obstacle to a lasting peace.