The explosions came a day after Somalia's interior minister warned of an explosives-laden vehicle somewhere in the capital.
The first blast occurred near the country's intelligence headquarters, police Capt. Mohamed Hussein told The Associated Press. He said the second occurred near parliament's headquarters, where the vehicle had tried to speed through a checkpoint before security forces engaged with the gunmen suspected of trying to attack the presidential palace.
The Aamin Ambulance service ferried 18 bodies and another 20 injured people after the blasts, director Abdirahman Abdulqadir told the AP.
The Somalia-based al-Shabab claimed responsibility for the attack via its radio arm, Andalus.
Mogadishu was the target of a truck bombing in October that killed 512 people in the deadliest attack in the Horn of Africa nation's history. Only a few attacks since 9/11 have killed more people. Al-Shabab was blamed.
Concerns have been high over plans to hand over the country's security to Somalia's own forces as a 21,000-strong African Union force begins a withdrawal that is expected to be complete in 2020.
On Thursday the head of the AU force, Francisco Madeira, said ending the pullout before 2021 "could bring about a serious risk of reversals that could derail the gains already made."
Somali forces, he said, are not yet ready.
Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.