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
The US House Ethics Committee has voted to release its report on former Republican Representative…
ABC News has agreed to pay $15 million to President-elect Donald Trump to settle a…
South Korea’s parliament has voted to impeach President Yoon Suk Yeol over his failed attempt…
Israeli war planes have carried out more than 100 air strikes in Syria on December…
President-elect Donald Trump has threatened to impose 100% tariffs on the BRICS countries if they…
Syrian troops have withdrawn from the city of Aleppo following an offensive by rebels opposed…