Somalia's president has sacked his police and intelligence chiefs after Islamist Shebab fighters launched a major assault against his palace for the second time this year.
"Both the police and intelligence chiefs were replaced, and the minister for the national security was named," Information Minister Mustafa Duhulow said on Wednesday.
A Shebab spokesman confirmed that the group was behind the attack late on Tuesday, and claimed their commandos had seized President Hassan Sheikh Mohamud's office inside the compound.
However, government dismissed their claims, saying the al-Qaeda-linked gunmen had been killed near the entrance.
"Of the four attackers, three were killed in the car park and one was captured," Duhulow said.
A security official had told AFP earlier that at least nine attackers were involved, and had all been killed. They had been dressed in government army uniforms.
Bomb disposal experts detonated several explosive devices, "including a suicide vest that one attacker was wearing that had failed to detonate", Duhulow said.
Mohamud, who was not in the complex at the time of the attack, later delivered a defiant message close to the charred wreckage of the car bomb gunmen used in their attempt to storm the compound.
"I am here to stay, with Allah's will ... I say to them, you will not kill us, and nor will you demolish our spirit," Mohamud said, also thanking the 22,000-strong African Union force who helped battle the attackers and guard the president.
Khalif Ahmed Ereg, a former intelligence chief, was named as Somalia's new national security minister.
The post had been empty after his predecessor resigned in April following a suicide attack against the national parliament while MPs were in a meeting, killing several guards and staff.
Mohamed Abdulahi Hassan was appointed as the new intelligence chief, and Mohamed Sheik Hassan as police chief.
The attack on Tuesday appeared to be a repeat of a Shebab assault against the presidential palace in February, when the Islamists, wearing Somali army uniforms, managed to penetrate the complex with a car bomb before being killed.