The attack targeted a police station in Mogadishu's Waberi neighborhood while President Hassan Sheikh Mohamud had been visiting a university, said Capt Mohamed Hussein.
He said the death toll was likely to rise, citing the horrific injuries suffered by the victims.
There was no immediate claim of responsibility for the attack, but the al-Qaida-linked Islamic extremist group al-Shabab often carries out such attacks.
Al-Shabab, which seeks to establish an Islamic emirate ruled by a strict version of Shariah law, has waged an insurgency against Somalia's weak UN-backed government.
Despite being ousted from most of its key strongholds in south and central Somalia, the group continues to launch deadly guerrilla attacks against the Somali government and African Union forces across large parts of the horn of Africa nation.