Somali and African Union soldiers captured a key area on the outskirts of Mogadishu from the insurgency on Friday, residents said.
AU soldiers used heavy weaponry, including anti-aircraft guns and tanks, to drive the al-Qaida-linked al-Shabab militia out of the village of Maslah during a battle that lasted several hours, they said.
"The fighting has stopped now, but al-Shabab fighters were forced out of here," resident Hussein Muhudin said by phone.
Somali troops are now searching homes in the area, he said.
Maslah was the last place insurgents could move freely within the capital. They used it to store weapons, train and carry out executions, and as a staging ground to carry out attacks on military bases in Mogadishu.
Lt. Col. Paddy Ankunda said Mogadishu is now under full AU and Somali control. The AU force commander said that it would help civilians return home.
"This operation is necessary to consolidate the security of Mogadishu. It will make it possible for the civilians to return to their homes and resume their normal lives," said Maj. Gen. Fred Mugisha. "I urge every peace loving Somali to give maximum cooperation towards this cause for peace."
Al-Shabab claimed to have inflicted heavy losses on the attacking force.
"They launched a counterattack on our ... forces but we inflicted heavy causalities on them," the militia said in a short statement.
A small number of residents who remained in their homes during the fighting said they fled after fighting subsided.
"We are running away to Balad now, it's a dangerous situation (here)," said resident Mahad Sheik. Balad is an agricultural town north of Mogadishu.
Mogadishu has long been a battleground during Somalia's 21-year-old civil war. But al-Shabab withdrew from most of its bases in August and recent pushes by the AU and Somali troops have helped bring partial security to more of the city.
Insurgents in disguise can still move freely and assassinations, suicide attacks and bombings are still very frequent. But the insurgency no longer holds set positions and it cannot operate checkpoints.
Somalia has been without functioning government since 1991.