Police suspect al-Qaeda-linked Islamist group al Shabaab of planting the bomb, which went off in the insecure Dayniile district where al Shabaab militants often hide.
Al Shabaab did not immediately claim responsibility.
Major Kadar Mohamed, a senior police officer, said three soldiers were among the dead and that the blast had targeted security forces.
Al Shabaab were pushed out of Mogadishu in 2011 by African Union peacekeeping troops but over the past year the rebels have carried out several large-scale attacks on high profile targets, denting gradual security improvements in Mogadishu.
Mother-of-three Fatuma Hassan, who was near the site of the bomb blast, said: "I could see several motionless people lying at the scene. The whole place was ruined and stained with blood."