Islamist al-Shabab rebels carried out a major bomb and armed attack on Somalia's presidential palace, penetrating the heavily fortified complex in the capital Mogadishu before blowing themselves up.
Somalia's internationally backed President Hassan Sheikh Mohamud and Prime Minister Abdiweli Sheikh Ahmed were not inside at the time of the attack late on Tuesday, officials said.
"There were at least nine attackers, all have been killed, and the situation is under control, the attack is over," security official Abdi Ahmed said.
"There were eight blasts towards the end of the fighting, believed to have been suicide vests. They detonated themselves."
An al-Shabab spokesman confirmed that the group was behind the attack, and claimed their commandos had managed to seize the president's office inside the presidential compound known as the Villa Somalia.
"Our commandos are inside the so-called presidential office," Abdulaziz Abu Musab said before the suicide blasts. "We are in control of the headquarters of the apostate regime.
"The enemy suffered high casualties during the operation, which is ongoing. The assault is a victory for us, since the foreign-installed government said that security was beefed up."
The attackers launched a two-pronged attack on the complex, police said, setting off a bomb at the rear of the compound and then storming in via another entrance. The attack came shortly after the start of iftar, when Muslims end the day's Ramadan fast.
It was not immediately possible to confirm reports that the embassy of Djibouti, which has troops in Somalia and whose mission is close to the palace, had also come under attack.
The UN's top envoy to Somalia, Nicholas Kay, said the attack was "an attempt to rob Somalis of the peaceful state they deserve".
"Terror will not win," he said.
Hard-line al-Shabab insurgents once controlled most of southern and central Somalia, including large parts of the capital, but were driven out of fixed positions in Mogadishu and Somalia's major towns by an African Union force.