Paramedics remove the body of a government soldier outside the Jazeera Hotel, the temporary home of Somalia's new president Hassan Sheikh Mohamud. The hotel was hit by two explosions Wednesday. (Mohamed Sheikh Nor/AP)

Two minutes into the news conference Wednesday, the first explosion shook the Jazeera Palace hotel. Bursts of gunfire followed, sending government officials and journalists diving to the floor. Within seconds, a rare day of hope in Somalia had been transformed into an all-too-common day of mayhem.

The hotel was under attack by three al-Shabab militants. All wore explosives-laden belts. One appeared to be disguised as a soldier. Their apparent target was Somali President Hassan Sheik Mohamud, who was elected two days ago.

By the end of the afternoon, at least seven people, including all three assailants, were dead outside the hotel, their bodies torn by bullets or explosives. Inside the hotel, any illusions that a peaceful Somalia was emerging from two decades of chaos and lawlessness were shattered.

“They want to destroy our hope,” said Mohammed Maie, a Foreign Ministry official who had arrived from Canada last year to help his country. “Anything can happen. These people, they are everywhere.”

Inside the hotel compound, a Washington Post reporter witnessed a soldier shoot one of the attackers several times as he tried to make his way inside the building. His explosives did not detonate.

The blood-soaked body of a security guard lay nearby. Three other bodies, including that of a soldier from the African Union, the U.S.-backed force mandated to protect Somalia’s government, could be seen outside the gate. Three other A.U. troops were injured, the force said in a statement.

On the street was the leg of what appeared to be one of the suicide bombers. He wore jeans and white sneakers. A severed head, presumably that of the attacker, lay a few feet away. Blood and flesh splattered military vehicles and walls.

The Islamist challenge

Somalia has been consumed by war and lawlessness since 1991, when the central government of President Mohamed Siad Barre collapsed. Two years later, mobs dragged the bodies of U.S. soldiers through Mogadishu during a U.N. peacekeeping mission, an event later depicted in the movie “Black Hawk Down.”

Mohamud, 56, an academic and civic activist, was elected Monday by Somali lawmakers in the war-torn nation’s first presidential vote of its kind in decades. Now, he was face to face with the country’s biggest security challenge — a hard-line Islamist militia still willing to dispatch its fighters to die, even as it has been pushed out of the capital and other parts of this Horn of Africa nation.

Somalia’s neighbors, including Kenya, Ethiopia and Djibouti, have dispatched their military forces to quell the Islamist extremists, who have shown a determination to spread their insurgency in the region. In 2010, al-Shabab, which is linked to al-Qaeda, orchestrated attacks in Kampala, Uganda, that killed more than 70 people watching the World Cup soccer finals. The militia has also been implicated in grenade attacks in Kenya.

Chaos at Mogadishu hotel

The Jazeera Palace is nestled in one of the most secure areas of Mogadishu, less than a mile from the heavily fortified A.U. base and international airport, and near the U.N. compound. On Wednesday, dozens of A.U. and Somali troops were protecting the hotel. Armored military vehicles were parked outside, topped with heavy machine guns.

Still, the militants managed to infiltrate the zone. They attacked just as the news conference was beginning, during a brief speech by visiting Kenyan Foreign Minister Sam Ongeri, suggesting that they had informants planted inside the hotel. But even as the explosion and gunfire reverberated, another battle was unfolding inside the news conference. Mohamud remained calm, though he winced at the sound of every gunshot. He didn’t take cover. He kept talking, determined not to let the chaos affect him.

“Somalia has turned a page and has opened a new page,” Mohamud told Ongeri and an assembly of local and foreign journalists.

A few moments later, the new leader conceded: “Things like what’s happening now outside will continue for some time.”

Then came a second explosion, about 7 1 / 2 minutes after the first. This time, it was farther down the street. It was the third suicide bomber, his explosives creating a crater the size of a small wading pool.

“Somalia has the momentum to move ahead,” Mohamud continued.

More bursts of gunfire.

“Security is our main target,” said Mohamud, nearing the end of his speech. “Our priority number one, priority number two, priority number three is security.”

The news conference ended. Mohamud and the other officials were taken downstairs. The A.U. and Somali troops prepared to evacuate them. In the hotel compound, the body of the militant who was shot dead by the soldier lay untouched, the explosives still wrapped around his torso. Soldiers parked their armored carriers next to the body in case it exploded as Mohamud left the hotel, where he had been staying until he could move into Villa Somalia, the presidential residence.

By then, al-Shabab had asserted responsibility for the attack, via Twitter. “HSM successfully targets a hotel near the airport in Mogadishu where a high profile meeting was being held,” read the first tweet, which used the acronym for the militia’s full name, Harakat al-Shabab al-Mujaheddin.

With each tweet, the militia grew bolder.

At 8.34 p.m., it sent out its last tweet: “HSM will continue fighting until the very last invader is eliminated from our land.”