"There were two blasts targeting the internal security compound near parliament," said Ibrahim Mohamed, a police commander, adding gunfire was continuing after the initial explosions.
In a statement posted on a jihadist website, the Al-Qaeda aligned Shabaab militant group claimed responsibility. There was no immediate toll given.
The Shabaab has been fighting to overthrow the internationally-backed government in Mogadishu for over a decade.
Despite losing towns and territory in recent years the group continues to carry out regular bombings and armed raids on government, security and civilian targets in the capital and elsewhere.