The attacker gained access to a military facility where he blew himself up among 200 young men looking to be recruited by the army, police told dpa.
The al-Shabaab militia, an insurgent group seeking an Islamist state in Somalia, claimed responsibility for the attack.
Another 16 people were injured with the number of fatalities expected to rise further, according to police.
The sound of the explosion could be heard in several parts of the city.
Al-Shabaab claimed on its radio station to have killed dozens of new recruits.
The group, which is linked to the al-Qaeda terrorist network, accused the government of exploiting unemployed young people to send them to fight against the militia.
Al-Shabaab has been carrying out attacks in Somalia and beyond for years to establish a theocracy based on Sharia law.
In recent weeks, fighting has been flared up again between government troops and the militia, particularly in the south and centre of the country.
GNA
PDC