A suicide bomber dressed in a military uniform triggered his explosives at Somalia's army headquarters on Wednesday, killing four soldiers, officials said.
Gen. Abdikarim Yusuf Dhagabadan, the chief of Somalia's armed forces, said he believed the bomber was targeting him for assassination as he was arriving for work. Dhagabadan said four soldiers died and 12 others were wounded, four seriously.
Al-Qaida-linked militants with al-Shabab have carried out several suicide bomb attacks in Mogadishu.
One soldier at the scene of the attack who gave his name only as Ali said the bomber feigned a stomachache outside the military headquarters in order to attract soldiers to him.
Dhagabadan said Somali forces opened fire on the bomber, killing him.
"A man walked toward me, then an armed soldier confronted him and ordered him to stop after which he turned around, took off his cap and turned toward the staff before he exploded," said Dhagabadan, who admitted that Somali soldiers were caught off guard.
"It will not be an incident that will frighten us. I promise, God willing, to deal a big blow to al-Shabab, those troublemakers who made a habit to kill and humiliate the Somali people," he said.
After the blast soldiers were on high alert, with fingers on the triggers of their guns. Blood stained nearby walls and human remains were scattered on the ground.
Somalia's weak military is backed by 9,000 troops from Uganda and Burundi who are fighting al-Shabab as part of an African Union peacekeeping force.
Al-Shabab has largely been pushed out of Mogadishu but continue to carry out suicide and roadside bomb attacks. Aside from battles with the African Union, al-Shabab also faces attack from Kenyan troops who entered southern Somalia last month. Ethiopian troops have also been reported to be attacking al-Shabab from the west.
Somalia's government on Wednesday condemned a string of attacks and explosions in Mogadishu.
The government said four recent bomb attacks _ excluding Wednesday's bombing _ have killed five people. One bomb was planted near a secondary school, another near a university. A bomb even went off in a Mogadishu hospital, wounding two people.
"After having been defeated in the battlefield they are engaged in a campaign of terrorizing the civilian population," said Information Minister Abdulkadir Hussein Mohamed. "It should be clearly evident to everybody that al-Shabab are nothing more than (murderers) of children and civilians in hospitals and schools."
Meanwhile, the U.N. said because of logistical and security challenges, 23 percent fewer people in need of food aid because of Somalia's drought and famine received food assistance in the month of November.
It said 2.6 million people were reached in October, while the figure in November was 1.45 million.
Associated Press reporter Malkhadir M. Muhumed in Nairobi, Kenya contributed.