A suicide bomber and one of the gunmen were also killed in the brazen attack just a half-mile from the presidential palace. The attack showed the insurgent group al-Shabab, which controls wide areas of Somalia, can penetrate even the few blocks of the capital under the control of the government and African Union troops.

Tuesday's well-planned assault came one day after al-Shabab warned of a new "massive war." Sheik Ali Mohamud Rage, an insurgent spokesman, said the attack by members of the group's "special forces" targeted government leaders, foreign agents and "apostates" at the $10-a-night Muna Hotel.

Survivors of the hourlong slaughter described seeing bodies strewn throughout the hotel and people scrambling to safety through windows. An 11-year-old shoeshine boy and a woman selling tea were among the dead.

A manager at the Muna Hotel, Abdullahi Warsame, said the attack was carried out by two gunmen who first fired on people sitting under a tree, then opened fire at the reception desk. The gunmen then moved to the second floor, where they battled security forces and armed parliamentarians, he said. The two fought until they ran out of ammunition, when one blew himself up, Warsame said.

After it was over, Somali government forces tied the body of one of the dead assailants to the back of a pickup truck and dragged it through the dusty streets of the capital, a scene eerily reminiscent of how bodies of dead American soldiers were treated following the disastrous Black Hawk Down battle of 1993 in Mogadishu.

Tuesday's attack only extended the stream of warfare that rattled Mogadishu on Monday, when 40 civilians died in fighting between al-Shabab and Somali and African Union troops.

Somalia's deputy prime minister told AP that 19 civilians, six members of parliament, five security forces and two hotel workers were killed Tuesday - a total of 32. Two attackers also were killed, said Abdirahman Haji Aden Ibi, the deputy prime minister. A government statement said 31 people were killed. There was no way to immediately reconcile the figures.

In Washington, U.S. State Department spokesman P.J. Crowley said the attack during Ramadan highlighted al-Shabab's "complete disregard for human life, Somali culture and Islamic values."

Al-Shabab, which has links to al-Qaida and boasts veterans of the Iraq and Afghanistan wars among its ranks, has grown deadlier in recent months. Last month, it claimed twin bombings in Uganda during the World Cup final that killed 76 people.

"The only intention of this group is to destroy the nation, massacre people and then finally hand the country to ruthless foreigners," Somali President Sheik Sharif Sheik Ahmed said. "So I call upon all Somali people to unite fighting against these enemies and help government forces."

The militant group is fighting to oust the 6,000 African Union troops from Uganda and Burundi that prop up the U.N.-backed Somali government - forces whom al-Shabab calls crusaders and invaders.

Al-Shabab calls itself a defender of the nation, but its interpretation of Islam is harsh. Al-Shabab forbids music, TV or letting women walk alone. Men must grow beards. Punishments can range from amputation to death by stoning.