The armed group al-Shabab launched an assault on the Somali parliament in Mogadishu, setting off a car bomb and storming the complex in an attack which killed at least 10 people.
Fighters on Saturday set off a car bomb outside the main gates and hit a guard post and with a suicide blast, before launching a gun assault on the compound.
African Union and Somali forces said the assault lasted four hours before the area brought under control. Witnesses told Al Jazeera that at least 10 people were killed.
The United Nations Security Council expressed "outrage" over the attack.
Abdulaziz Abu Musab, al-Shabab's military spokesman, told the Reuters news agency: "The so-called Somali parliament is a military zone. Our fighters are there to carry out a holy operation. We shall issue a comprehensive report after the conclusion of the operation."
Farah Hussein, a police colonel, told the agency: "A car bomb exploded at the gate of the parliament house - then it was followed by a suicide bomber explosion. So far we have confirmed four policemen dead."
The terrorists have once again shown that they are against all Somalis.
"The politicians and the other workers were rescued as soon as the car bomb exploded. But the terrorists are still firing from inside a mosque nearby," he added.
The AP news agency reported that politicians were inside the building as the attack began. Two were wounded by gunfire, according to Mohamed Ali, an MP.
The agency quoted Mohamed Nor, another MP, saying that the army had failed to protect them "The enemy can now access everywhere," the agency quoted him as saying
A statement from Somalia's prime minister, Abdiweli Ahmed, said: "The terrorists have once again shown that they are against all Somalis, by killing our innocent brothers and sisters. These cowardly, despicable actions are not a demonstration of the true Islamic faith.
"This attack will not deter the government of Somalia from continuing to hunt down and destroy the terrorists and build a peaceful Somalia that terrorists will never rule over."
Abdikarim Hussein Guled, Somalia's national security minister, resigned following the attack.
The parliament building is about 300 metres from the Somali presidential palace, and is guarded by African Union and Somali forces.
Al-Shabab was forced out of Mogadishu about two years ago, but is still capable of launching complex attacks in the most-guarded areas of the city.
It has launched attacks in neighbouring Kenya, which has sent troops across the border to fight the group. Last September, the group killed 67 people at the Westgate Mall shopping centre in the Kenyan capital, Nairobi.