"We have swept them from the area. Madina and Dharkenley districts are now in our hands," Abdiqadir Odweyne, a senior police officer, told the Reuters news agency on Tuesday.
Officials said that security forces had also regained control of a police station in the Yaqshid district, north of Mogadishu, from opposition fighters.
Residents reported seeing dozens of bodies in the streets of the city after the fighting, but no confirmed death toll was immediately available.
Ali Bile, a hospital administrator, said that scores of wounded had been admitted for treatment.
"We have 138 people in our hospital - they're improving now," he said. "Doctors in our hospital are very busy treating the wounded civilians in the wards."
Fourteen out of Mogadishu's 16 neighbourhoods are now under government control, according to Mohammed Abdi Gandi, Somalia's defence minister.
"That means we are making progress," he said.
"We presently have the situation well under control and we have enough soldiers to hold on and repel the extremist aggression on the country."
But Abdullah Youssef, secretary-general of Hizbul Islam, an armed group, told Al Jazeera that the opposition forces would regain any ground they had lost.
"If we were the ones who initiated the attack, the fighting would have been next to Mecca Street and the presidential palace. But we assure you that they will have to retreat," he said.
Hizbul Islam has allied with al-Shabab, another armed group, in an attempt to force the interim government from power, accusing Ahmed of being a traitor because he signed a UN peace deal in January and joined the government.
Ahmed was previously the leader of the Islamic Courts Union, which seized much of south and central Somalia from the government in 2006.
Colonel Mohamed Hashi, a senior Somali police officer, told the AFP news agency that "many people are fleeing the battle zones".
Dharkinley has been one of the rare calm districts of Mogadishu in recent years and has become home to many of those displaced by the fighting in other districts.
But on Tuesday, residents began to packed up their belongings and moved out, many heading for the displaced persons' camps on the edge of the city.
About 70,000 people are believed to have fled Mogadishu since May 7, when armed groups stepped up their attacks on government.
"The recent fighting has made the humanitarian crisis in Somalia even worse," Hassan Noor of the UK-based Oxfam aid organisation.
"Tens of thousands are on the move, hundreds of thousands are displaced and more than three million are in dire need of aid."