Sixteen people, including nine attackers, are believed to have died after gunmen stormed the city's main court buildings.
Later a car bomb was detonated on the road to the airport, killing three, including two Turkish aid workers and the attacker.The Islamist militant group al-Shabab says it carried out the attacks.Al-Shabab, which has links with al-Qaeda, has been blamed for a series of attacks in Mogadishu in the last two years.But correspondents say Sunday's violence is the worst seen in the city since al-Shabab was pushed out of the city by AU and Somali forces in August 2011.
The Islamist group still controls most villages and rural areas of Somalia.BBC reporter Mohamed Ibrahim at the scene says armed intruders entered the court in the capital and began firing, after which there was an explosion.A gunfight followed as security forces exchanged fire with the attackers.Witnesses said at least one car bomb was used in the attack.
"Armed men entered the court and then we heard a blast. Then they started opening fire," witness Hussein Ali, who works at the courts, told Reuters news agency.
Ugandan troops - part of the African Union force stationed in Mogadishu - arrived at the scene shortly after the shooting started.The Somali government said that nine gunmen had been involved in the assault, and all had now been killed.
Six of them detonated suicide vests, it said.Aid workers killed Other witnesses said the attackers were dressed in Somali military uniform.
People were seen trying to escape the violence from the upper floors of the court buildings by breaking windows and climbing out of the buildings. Some were said to be senior officials.Our reporter says the courts are located in one of the busiest parts of the city, and were full of people when the attacks happened - Sunday is a normal working day in Somalia.
A second car bomb was detonated later, outside a building housing security forces on the road to the airport.It was set off as a convoy carrying Turkish aid workers passed, killing two of them.
Survivors are helped to escape from a window at Mogadishu’s court complex in Mogadishu, Somalia, Sunday, April 14, 2013. Militants launched a serious and sustained assault