Somalia's president sacked his police and intelligence chiefs on Wednesday 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.
Recent Shebab attacks have targeted key areas of Somalia's government or the security forces, apparently to discredit claims the authorities are winning the war against the Islamists.
A Shebab spokesman confirmed that the group was behind the attack late on Tuesday, and claimed their commandos had managed to seize President Hassan Sheikh Mohamud's office inside the compound known as Villa Somalia.
However, government dismissed their claims, saying the al-Qaeda-linked gunmen had been killed near the entrance of the compound.
“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 added.
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 that 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.
The Shebab commander in Mogadishu, Sheikh Ali Mohamed Hussein, vowed last month that the capital would become the “frontline” for assaults.
Hardline Shebab 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 the African Union force.
AU troops launched a fresh offensive in March against Shebab bases, and although they seized a series of towns, the insurgents are thought to have fled in advance and suffered few casualties.
The Shebab have also increased their scope of operations since last September, when they launched an attack on Nairobi's Westgate mall in which at least 67 people were killed. - Sapa-AFP