Somalia's al-Qaeda-linked al-Shabab rebels have launched a major suicide attack against the heavily fortified presidential palace.
A huge car bomb exploded on Friday at the perimeter of the central Mogadishu complex, and a group of about a dozen suicide attackers breached the Villa Somalia compound.
Al-Shabab rebels immediately claimed responsibility.
The United Nations' special envoy to Somalia, Nick Kay, said the country's president, Hassan Sheikh Mohamud, had telephoned to say he was unharmed in the attack on the complex, which is one of the best-defended locations in the war-torn country.
"There is a large attack on the presidential palace," police officer Mohamed Ali said. "Initial reports are that a suicide car bomber hit the gate and exploded, then men with guns followed."
Another source said he saw at least nine gunmen attack.
"Security forces are dealing with terrorists who blew up a car ... and there is exchange of fire," said Ahmed Moalim Adan, a security official near the scene of the attack. "We have no details of the casualties but of course there are casualties."
Witness Hussein Isa said the attackers were fighting inside the presidential compound.
"A suicide bomber rammed a car full of explosives into the perimeter wall of the presidential palace and another one with heavily armed men penetrated the area where the first one hit," the witness said. "There is heavy exchange of gunfire continuing inside the building but we cannot tell what is happening."
A military spokesman for al-Shabab said the group was behind the attack.
"Our commandos have attacked the so-called presidential palace in order to kill or arrest those who are inside," Sheikh Abdul Aziz Abu Musab said.
"We are still holding some of the buildings and the fighting is continuing. The enemy had suffered a great deal of harm but I don't have the exact casualty figures."
The attack came just a week after the militants carried out a suicide car bomb attack at the gates of Mogadishu's heavily fortified international airport, and the al-Shabab spokesman said the group wanted to show "that no place is safe for the apostate government".
In a message on Twitter, UN special envoy Nick Kay said the president "just called me to say he's unharmed" and the "attack on Villa Somalia had failed".
"Sadly some lives lost. I condemn strongly this terrorism," Kay's message said.