Most of southern and central Somalia is held by Islamic insurgents and peacekeepers and government forces come under regular attack in the capital.
Mayor Mohamed Osman Ali said it was unclear who was behind the attack.
"A suspected suicide car bomb exploded about 200 meters (yards) away from an African Union base," he said. "A government police officer suspected the car, which was driving at high speed, and opened fire. The suicide bomber then blew himself up."
Ali said one of the dead was a police officer and the others were all civilians. Fourteen others were wounded, he said. Three of the dead were women.
Ali Muse, who works for Mogadishu's ambulance service, said an exchange of gunfire and mortars following the bombing killed one person and wounded 18.
AU spokesman Bahoku Barigye said no peacekeepers were wounded in the attack. Last August, a car bomb attack targeted barracks housing Burundian peacekeepers.
Officials in Somalia's crumbling government warned of a security vacuum after their Ethiopian allies withdrew their last soldiers in early January. The government now controls only the parliamentary seat of Baidoa and a few city blocks in the capital.
Last month, the president resigned after months of government infighting. The Somali parliament is due to choose his replacement on Monday in Djibouti.
Ugandan army spokesman Maj. Felix Kuraigye said the 700 Ugandan troops headed for Somalia should be there by the end of the month if transport arrangements are finalized.
The arid, impoverished Horn of Africa nation has not had a functioning government since 1991, when clan-based warlords overthrew a socialist dictator.
Pirates operate off its lawless coastline and analysts fear the failed state is a harbor for international terrorists.