A nine-man suicide commando blasted its way into Mogadishu's main court complex Sunday, some blowing up their explosives vests while others sprayed gunfire on civilians in a three-hour rampage.
According to Somali officials, five civilians and all attackers were killed in the raid while an almost simultaneous car bomb attack on a Turkish aid convoy killed another five in the city's worst day of violence in months.
A spokesman for the Al Qaeda-linked Shebab claimed responsibility for the attack, which the country's chief justice escaped unharmed, and promised more against the fledgling UN-backed government that took over last year.
"Nine attackers died during the incident... six detonated themselves, and three were shot dead by security forces," Interior Minister Abdikarin Hussein Guled told reporters.
He said the government had regained control and added that a casualty toll was being compiled, amid fears the initial figure of five dead civilians could rise.
After Somali forces eventually ended the raid, during which a car bomb also exploded, chaos still engulfed the area and an AFP reporter saw medics evacuating wounded through the courthouse's shattered windows.
"Some of the terrorists are still inside the court building and they are wearing explosive vests," Fadumo Ali, a civilian trapped inside the building, told AFP during the raid from a mobile phone.
Shebab spokesman Sheikh Ali Mohamed Rage claimed only five suicide attackers died in the raid.
"This was a holy action which targeted non-believers who were in a meeting within the court complex. We will continue until Somalia is liberated from invaders," he told AFP.
The insurgent organisation used to control most of the seaside capital until it abandoned fixed positions in August 2011 but it has since carried out a string of attacks against the UN-backed government.
As the drama inside the court complex still unfolded, five people were killed when a remote-detonated car bomb near the airport struck a convoy carrying Turkish aid.
"Five people, two of them women who were passing by the area were killed in the car bomb attack," Hassan Moalim, who witnessed the attack, told AFP.
He said two of the bodies were charred beyond recognition.
An official from the Turkish Red Crescent confirmed to Turkish news television channel NTV that the organisation suffered casualties.
"We unfortunately lost our Somali driver in the blast," said Ahmet Lutfi Akar, the head of the Turkish Red Crescent. "Three Turks were also mildly injured but they are in hospital now and doing well."
Turkey has recently taken a leading role in Somalia and is very active in reconstruction and aid projects across the country, which has been left in ruins by two decades of almost uninterrupted conflict
A semblance of normalcy had returned to the war-battered seaside capital since mid-2011, when the Shebab pulled out and started losing most of their strongholds across the country.
A regional military offensive has forced many Shebab fighters to retreat to the mountains in northern Somalia but the insurgents have reverted to guerrilla tactics and carried out several bomb attacks in Mogadishu.
"This attack is nothing but a sign of desperation by the terrorists, who've lost all their strongholds and are in complete decline right across Somalia," Somalia's President Hassan Sheikh Mohamud said in a statement.
The courthouse is in the heavily-guarded administrative quarter of the capital and several senior officials were caught in the chaos.
"The chief justice and other senior judiciary officials are all safe and sound, they were rescued unharmed but unfortunately a number of civilians and security personnel were killed in the attack," police commander Mohamed Yusuf said.