Observers say there has been a change in tactics, with Islamists switching from hit-and-run raids to sustained attacks against peacekeepers.
Somalia has been wracked by conflict since 1991, when former President Mohamed Siad Barre was overthrown.
Ethiopia intervened in 2006 to help the government oust Islamist forces from the capital and surrounding regions.
The Islamists then launched an insurgency against Somalia's transitional government and its Ethiopian allies.
Tuesday's clashes happened in the south of the city. Our reporter says heavily armed insurgents attacked the AU base at K4 - a strategic junction in the south of the city linking the airport and the presidential palace.
The sounds of deafening gunfire and bombardments could be heard throughout the city overnight, our correspondent says.
Peacekeepers have generally been considered friendly since their arrival last year, and residents have been upset by the scale of their retaliation, our reporter says.
Maj Bahoku Barigye, an spokesman for the African Union Mission to Somalia (Amisom), said the peacekeepers had not suffered any causalities and were acting in self defence.
"We are not using any heavy arms," he told the BBC.
"We target a specific area where people are shooting at us from, and that is it, we don't go outside, we don't go beyond that."
Our correspondent says people living by the AU bases are fleeing their homes - on minibuses, donkey carts or on foot.
The only way out of this mess at the moment is to have a successful negotiation
Academic David Shinn
"We could no longer watch the shocking incidents and what happened to our neighbours, who were either killed or injured, my children could not bear the shelling, that is why I have decided to escape," a mother of five told the BBC's Focus on Africa programme.
An elderly man said: "I have escaped from my house because throughout last night artillery shells had been pounding on us."
Local human rights worker Ali Shiekh Yaasiin said an estimated 15,000 to 18,000 people had left the city in the past few days to join other displaced people outside the city.
David Shinn, a former US diplomat who teaches at the George Washington University, said fighters from the hardline al-Shabab militia were trying to assert their authority in order to force the Ethiopians out.
They are trying "to show that they are in a position to perhaps even take control of Mogadishu if the Ethiopian forces were to leave", he told the BBC.
'No lost cause'
People have started fleeing the worst violence in months
Maj Barigye said it was unrealistic to expect a quick resolution to Somalia's long-running conflict.
"There is no lost cause here," he said.
"It's just a question of time, a question of patience, it's a question of tolerance, it's a question of understanding."
Only Uganda and Burundi have contributed troops to the AU peacekeeping force, which has just 2,000 troops of the 8,000 planned.
But Mr Shinn said adding more peacekeepers would not help.
"The only way out of this mess at the moment is to have a successful negotiation between moderates and the Alliance for the Re-Liberation of Somalia, the ARS, and the transitional federal government," he said.
The UN has been leading peace negotiations over Somalia in neighbouring Djibouti, but al-Shabab has so far rejected the process.
A ceasefire due to be signed at the end of last week has been delayed for another month.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.