The attack raised new questions about the ability of Somalia's weak government to control even the small area of the capital it holds. African troops protecting the government wage near daily battles with Islamic militants who hold much of central and southern Somalia.
More than three dozen students had gathered to receive their diplomas at the ceremony at the Shamo Hotel.
The assailants hit one of Somalia's most important efforts to extricate itself from anarchy and violence, explaining the presence of so many top government officials. The former medical students among the graduates came from only the second class to receive diplomas from the medical school.
The first class graduated a year ago. Before then, almost two decades has passed since anyone earned a medical degree in Somalia. In the December 2008 ceremony, held at the same hotel, the graduates proudly hoisted diplomas into the air. This year, there was mayhem as the bomb went off, leaving the dead and wounded in bloody heaps.
"What happened today is a national disaster," said Somali Information Minister Dahir Mohamud Gelle, who confirmed that the ministers for education, higher education and health were killed in the blast. The ministers for sports and tourism were wounded.
No group immediately claimed responsibility, but suspicion fell upon the militant group al-Shabab, which has ties to al Qaeda, controls much of the country and has carried out past suicide attacks.
"A man who disguised himself as a woman, complete with a veil and a female's shoes, is behind the explosion," Gelle said. "We even have his picture."
Saudi-owned Al-Arabiya television said its Somali cameraman, Hassan Zubeir, died. Two other Somali journalists working for local outlets also died, said Bashir Khalif, a reporter for the Somali government's radio service.
In total, 15 people plus the suicide bomber died, the Somali information minister said. However, a statement from the African Union's mission in Somalia said 19 people were killed. The reason for the discrepancy was not immediately clear.
Top Somali officials including the president and prime minister met for an emergency session at the presidential palace after the attack.
Several hundred people had gathered inside a decorated ballroom in the Shamo Hotel to celebrate the graduations of the medical, computer science and engineering students from Benadir University. The school was established in 2002 by a group of Somali doctors who wanted to promote higher education in a country where physicians have become the victims of the seemingly endless violence. Medical degrees are obtained after six years of study.
The president of Benadir University said 43 students were taking part in the graduation ceremony. The university's Web site says more than 500 students are enrolled and that the school "strives to establish an open system of innovation and critical thinking similar to that in the developed countries."
Attendees were sitting on plastic chairs facing a small stage when the bomb went off.
The European Union and the African Union condemned the attack.
Somalia has been ravaged by violence and anarchy since warlords overthrew dictator Mohamed Siad Barre in 1991, then turned on each other. A moderate Islamist was elected president in January in hopes that he could unite the country's feuding factions, but the violence has continued unabated.
In October, insurgents fired mortars at the airport as the president was boarding a plane, sparking battles that killed at least 24 people. Witnesses said mortars also were fired toward the airport around the time the president returned from his trip.
And in September, Islamic insurgents posing as U.N. personnel detonated suicide car bombs in an African Union peacekeeping base, killing 21 people.
Before 2007, suicide bombings were unheard of in Somalia. Since then it has become increasingly frequent. In October 2008, there were five apparently co-ordinated attacks in key urban centres of northern Somalia. A young Somali man from Minneapolis Shirwa Ahmed is believed to have carried out one of the suicide bombings.
Thursday's attack is the second time this year members of government have been killed in a suicide bombing. In June, the national security minister died in a suicide bombing that killed at least 24. Al-Shabab claimed responsibility.
Somalia's lawlessness has spread security fears around region and raised concerns that al Qaeda is trying to gain a foothold in the Horn of Africa. The anarchy has also allowed piracy to flourish off the country's coast.
Of the three ministers killed in the blast, one was a woman Qamar Aden Ali, the health minister. Ibrahim Hassan Adow, the minister for higher education, and Ahmed Abdullahi Wayel, the minister for education, also died. There are 37 ministers in Somalia's government, according to a Web site on the Somali government kept by the CIA.