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
At least 158 people have died in Spain's worst flooding disaster in generations. On October…
Google has been fined two undecillion (a two followed by 36 zeroes) roubles by a…
Embarking on a home remodel is an exciting journey, promising enhanced comfort, increased property value,…
The US presidential candidates continued to campaign across key swing states on October 20. Footage…
Elon Musk has said he will give away $1 million a day to a registered…
India and Canada have decided to expel their top envoys along with other diplomats as…