Eyewitnesses said a truck carrying explosives was driven up to a checkpoint at the entrance to a government ministry and detonated.
A spokesman for the Islamist militant group al-Shabab told the BBC it had carried out the attack.
It is the largest attack since al-Shabab withdrew its forces from Mogadishu in August.
Rescue workers said more than 50 people had been injured in the blast. Many of the victims were soldiers and students who had been waiting at the education ministry.
The UN-backed transitional government condemned the attack and said no senior government officials were hurt in the blast. Government members were meeting in the building near the blast site at the time.
“The attack shows that the danger from terrorists is not yet over and that there are obviously still people who want to derail the advances that the Somali people have made towards peace,” it said in a statement.
Among those killed were soldiers guarding the offices and students who had been queuing for exam results at the education ministry, hoping to gain a scholarship to study in Turkey.
Meanwhile back in hell another suicide bomber turns up looking for paradise and a stash of virgins only to be severely disappointed.
Newswarped reiterates our stance that all suicide bombers should have a convention in the desert and practice their technique.