The bomb has blown a hole in the wall of the presidential palace, followed by a fierce gun battle inside, officials say.
It is not clear how many people died in the attack.
President Hassan Sheikh Mohamud has told the UN envoy to Somalia he was not harmed, envoy Nick Kay has tweeted.
The al-Qaeda-linked group al-Shabab has said it carried out the attack, which it said was still ongoing.
This is the first time that al-Shabab fighters have entered the presidential palace, known as Villa Somalia.
The heavily guarded complex is home to the president, prime minister, speaker of parliament, other ministers and a mosque, which was hit during the attack.
Some of the attackers were wearing suicide vests, police sources have said.
Senior police officer Abdikadir Ahmed told the Reuters news agency fighting was underway in the house of a military commander within the presidential compound, near the palace.
“The car bomb hit and exploded and other al-Shabab cars with armed men drove inside the palace, and heavy fighting is still going on,” he said.
Security Minister Abdi Karim Hussein said that some of the attackers had been killed and others captured. He also said all of the country’s leaders were safe.
Al-Shabab military spokesman Sheikh Abdul Aziz Abu Musab said militants were still in control of some buildings inside the presidential compound.
“Our commandos have attacked the so-called presidential palace in order to kill or arrest those who are inside,” he told the AFP news agency.
Nick Kay said the attack on Villa Somalia had “failed”.
“Sadly some lives lost. I condemn strongly this terrorism,” he said.
Al-Shabab was driven out of Mogadishu in 2011 but it still controls many smaller towns and rural areas of the country.
Some 22,000 African Union troops are helping the government battle al-Shabab
Image source: Wikimedia Commons President-elect Donald Trump celebrated his election victory at the Ultimate Fighting…
Millions of voters across the US chose to return Donald Trump to the White House…
Donald Trump declares victory in the US election as he addresses jubilant supporters in Florida.…
Stocks around the world are rising as Donald Trump appears to be on the cusp…
Donald Trump has won Pennsylvania, North Carolina and Georgia and taken a lead over Kamala…
Quincy Jones, the celebrated musician and producer who worked with Michael Jackson, Frank Sinatra, Ray…