"A suicide bomber tried to strike the police post in front of the port but the security forces shot him and the vehicle exploded," said police officer Abdukadir Ahmed.
"Two police officers and five civilians were wounded," he said, AFP reported.
There was no immediate claim of responsibility.
Witnesses said officers opened fire on the vehicle after it failed to stop at the police checkpoint.
Also on Saturday, a land mine went off in a restaurant on the outskirts of the city of Baidoa, killing four people.
Ali Abdullahi, an official with the Southwestern regional state, told AP that the mine was detonated by remote control as people were dining during the morning rush. Several others were wounded.
Somalia has suffered near-continuous conflict for almost 30 years, while the internationally-backed government in Mogadishu has been fighting al-Shabaab terrorists since 2008.
Bombings and other terrorist attacks are common in Mogadishu, although few have been recorded in recent months.