The blast sent plumes of smoke into the sky and triggered gunfire, witnesses and state-owned media reported.
“So far we have carried 20 dead people and 30 injured from the blast scene,” Dr Abdulkadir Aden, founder of AAMIN Ambulance services, told Reuters news agency.
The blast occurred at the Luul Yemeni restaurant near the port, witnesses said.
“A speeding car exploded at Luul Yemeni restaurant. I was going to the restaurant but ran back when the blast shook and covered the area with smoke,” said resident Ahmed Abdullahi.
Police Spokesman Sadiq Ali Adan blamed the attack on the armed group al-Shabab, which is linked to al-Qaeda and often targets Mogadishu with bombings. The Luul Yemani restaurant also was attacked last year.
At least one building near the restaurant collapsed after the blast and people were feared to be trapped in the rubble. The bombing occurred at dinner time when the restaurant was full.
No one claimed responsibility for the blast.
“The blast was very heavy and caused massive destruction and civilian casualties. The operation is still going on to establish the exact number of casualties,” said Security Officer Mohamed Osman.
Al-Shabab frequently carries out such bombings in Somalia and elsewhere as part of its campaign to topple the Horn of African country’s central government.
Security in Mogadishu had been especially heavy with thousands of government forces deployed in anticipation of a planned demonstration on Saturday by an alliance of opposition leaders over the country’s delayed national election. The demonstration was later postponed.