MOGADISHU, Somalia — Islamist militants wearing Somali military uniforms stormed a hotel favored by lawmakers in the war-battered capital Tuesday, firing indiscriminately and killing 32 people, including six parliamentarians.

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 that 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 and dragged it through the dusty streets, a scene eerily reminiscent of how bodies of dead U.S. soldiers were treated after 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. Two attackers also were killed, said Abdirahman Haji Aden Ibi, the deputy prime minister.

Al-Shabab is fighting to oust the 6,000 African Union troops that prop up the U.N.-backed Somali government.