Jihadist rebels claimed the attack.
“We have so far collected 18 bodies and 20 wounded persons from one of the blast scenes,” Abdukadir Abdurahman Aden of the Aamin Ambulance told AFP.
The bombings targeted the presidential palace and a city hotel, police said.
The first blast, followed by gunfire, occurred at a checkpoint close to Villa Somalia, the name for the seat of government, while a second followed soon after at a hotel.
“I can confirm an attack in the vicinity of the presidential palace,” said police officer Ibrahim Mohamed.
“Another car loaded with explosives went off close to a recently opened hotel,” Mohamed added.
The Shabaab Islamist militant group claimed the attacks in a statement posted online, saying it was targeting the government and security services.
The blasts follow weeks of relative calm in Mogadishu.
According to officials, the main attack involved the use of a vehicle loaded with explosives attempting to breach a checkpoint leading to the presidential palace but security forces prevented the assault.
“The security forces foiled the intent of the terrorists. They were aiming for key targets but they could not even go closer, there were five of them killed by the security force,” said Abdulahi Ahmed, a security officer.
“The situation is back to normal and the security forces are in control,” he added.
The Shabaab is fighting to overthrow Somalia’s internationally-backed government. In October it carried out its deadliest-ever bombing, killing over 500 people.
In the wake of that attack Somalia’s government declared a fresh offensive against the group and US drone strikes have increased in frequency.
While the militant group was pushed out of the capital in 2011 by an African Union force it continues to control large parts of the countryside and launches regular attacks on government, military and civilian targets.