Capt. Mohamed Hussein said the bomber tried to speed through a checkpoint but was stopped by security forces, prompting him to detonate the vehicle near the gate of Howlwadag district headquarters.
He said another four people were wounded, mostly young students at a nearby Islamic school. Officials warned there could be more casualties as the blast pulled down nearby buildings including a mosque.
"They have literally failed to achieve their goal of inflicting maximum casualties," Hussein said, accusing the al-Qaida-linked extremist group al-Shabab of carrying out the attack.
There was no immediate claim of responsibility for the explosion, which shattered a period of calm in seaside Mogadishu. The Somalia-based al-Shabab often targets the capital with bombings, including a truck bombing in October that left at least 512 people dead.
Somali troops are meant to take over the Horn of Africa nation's security in the coming years from an African Union force but concerns about their readiness remain high. The U.N. Security Council recently voted to delay the reduction of troops in the AU force from October to February and the target date to hand over security to Somali forces to December 2021.