Police said at least nine people had been killed and several wounded. Most of the victims were young men who were entering the Pizza House when the vehicle exploded, Captain Mohamed Hussein said.
A burst of gunfire was later heard inside the restaurant, Hussein said.
The gunmen "were dressed in military uniforms. They forced those fleeing the site to go inside" the restaurant, witness Nur Yasin told The Associated Press.
Security forces rescued Asian, Ethiopian, Kenyan and other workers at Posh Treats as the attack continued, Hussein said.
More From This Section
The Somalia-based al-Shabab often targets high-profile areas of Mogadishu, including hotels, military checkpoints and areas near the presidential palace. It has vowed to step up attacks after the recently elected government launched a new military offensive against it.
The extremist group also faces a new military push from the United States after President Donald Trump approved expanded operations, including airstrikes, against al-Shabab.
On Sunday, the U.S. Military in Africa said it carried out an airstrike in southern Somalia that killed eight Islamic extremists at a rebel command and logistics camp.
Somalia President Mohamed Abdullahi Mohamed confirmed that airstrike and said such attacks would disrupt the group's ability to conduct new attacks.
The 22,000-strong African Union multinational force, AMISOM, which has been supporting the fragile central government, plans to start withdrawing in 2018 and leave by the end of 2020.
Also today, the UN Security Council unanimously adopted a resolution extending the UN political mission in the Horn of Africa nation, which is trying to rebuild after more than two decades as a failed state, until March 31, 2018.
The resolution recognized that "this is a critical moment for Somalia.