At least one person has died with one army official saying as many as six people have lost their lives, and several people have been wounded.
The prime minister and president are said to be unharmed.
Both men took office following elections last September deemed to be the first fair such vote for 42 years.
Hassan Sheikh Mohamud, an academic and civic activist, beat the incumbent in a run-off vote to become president.
He then appointed his close associate, former businessman Abdi Farah Shirdon as prime minister.
Details of what exactly happened are not yet clear, but the attacker appeared to have been close to the entrance to the sprawling compound known as Villa Somalia that houses both the president’s and prime minister’s offices.
One guard told Reuters news agency that one soldier had died and two others wounded, but a military official told AFP news agency that six people had died and several had been injured.
“The bomber was sitting near a perimeter wall and detonated himself in the midst of a group of security forces,” the official, Abdukadir Ali, told AFP.
No-one has yet claimed responsibility for the attack.
The new government is trying to rebuild the country after 20 years of conflict.
One of its biggest challenges is the al-Qaeda-aligned Islamist group, al-Shabab, which still controls large areas of rural southern and central Somalia.
Source:- BBC News + News Agencies