At least 118 inmates escaped from prison after heavy rain damaged the facility
It was unclear what caused the explosion but Islamist militant group al Shabaab frequently carries out bombings in Mogadishu and other parts of Somalia against government military and other targets.
The group is trying to remove the Western-backed central government and establish its own rule based on its strict interpretation of sharia law.
Al Shabaab's militants also carry out attacks outside Somalia especially in Kenya to pressure the country to return its troops who form part of the peace keeping force AMISOM that helps defend the central government.
Its latest assault in Kenya, a suicide and gun attack at an office and hotel complex in the capital Nairobi last month killed 21 people.