"Al-Shabaab suicide bombers have attacked the court and regional headquarters area," said Abdirahman Mohamed, an intelligence officer in Mogadishu. "At least one of them detonated himself, leaving several dead. There are still several of them fighting the security forces inside the building."
Ahmed Abdulkadir, a police officer at the courthouse, said five people, including civilians, were confirmed dead. "The death toll could be higher since the situation is not under control yet," he told AFP.
Police officer Abdiweli Hussein said Somali forces, police and African Union Mission in Somalia troops are trying to restore security to the area.
Witnesses said the suicide bombers and the gunmen, who were dressed in Somali military uniforms, stormed the main court building and started shooting at the security guards who fired back.
It is believed that senior judiciary officials including a Supreme Court judge were in the building when the gunmen stormed it. It is not known whether court officials were among the casualties.
Al-Shabaab has claimed responsibility, saying "5 martyrdom seekers" attacked the courthouse. "The Mujahideen have today carried out some daring attacks against the apostate Somali regime in Mogadishu," the group said via Twitter.
Somali President Hassan Sheikh Mohamud condemned the attack. "This attack is nothing but a sign of desperation by the terrorists, who have lost all their strongholds and are in complete decline right across Somalia," he said in a statement.
Several people were also wounded minutes after the courthouse incident when a remote-detonated car bomb went off as a Turkish aid convoy passed near the airport.
"The car was filled with explosives and was parked by the roadside," said witness Nur Osman. "I can still see the shell of the burning car. Several people including security guards have been evacuated. I do not know how badly they have been injured," he told AFP.