Thousands of internally displaced Somalis have been forced to flee again to avoid heavy fighting in the Afgoye corridor, just south of the capital.
A BBC correspondent says he saw hundreds of loaded lorries and small vehicles streaming into Mogadishu.
African Union forces say they launched a major assault on Wednesday on Afgoye, a stronghold of Islamic militants.
Up to 400,000 people live in the area – in sprawling roadside camps, amid unsanitary conditions and rife hunger.
The BBC’s Mohammed Dhore in Mogadishu says people fled to the Afgoye corridor when fighting in the capital escalated in 2007.
They are now heading back to Mogadishu, he says, to escape heavy artillery shelling and mortar fire as African Union and Somali government troops battle al-Shabab militants for control of Afgoye, about 30km (18 miles) from Mogadishu.
Our correspondent says thousands will be returning to already overcrowded camps in the capital – with no running water and no electricity.
But one resident of the Afgoye corridor told the BBC she would rather be in Mogadishu and seek shelter in a bombed-out, but concrete building than risk staying in a makeshift cloth-and-plastic shelter as fighting rages.
Our correspondent says the African Union forces have 100 tanks and armoured vehicles within 10km of Afgoye.
If they take the town it would be a major blow to al-Shabab – and help secure the capital, where the al-Qaeda-linked group has staged a series of suicide attacks in recent weeks..
Al-Shabab still controls many southern and central areas of the country – but it is under pressure on several fronts, including from Ethiopian and Kenyan forces sent into Somalia to push back the militants.
Somalia has been without an effective central government since 1991 and has been convulsed by conflict since then.
Nearly 1.5 million Somalis have been forced from their homes and are internally displaced.