NAIROBI, Kenya — Militants detonated a deafening car bomb at the gates of a popular hotel in Somalia on Wednesday evening, and gunmen then stormed the hotel, leaving at least 15 people dead and creating a fiery scene of wrecked cars, crumbled buildings, panic and smoke that stretched for blocks in the heart of Mogadishu, the capital.

The Somali authorities said government forces were battling room to room in the hotel, the Ambassador, against a few heavily armed men. A spokesman at a hospital said more than 40 people had been wounded in the attack.

The Shabab, a Somali militant organization that has attacked several other hotels in similar fashion, claimed responsibility for the assault.

Somalia has been increasingly violent. After years of retreats and defeats, the Shabab have been stepping up attacks on civilians, peacekeepers and Somalia’s fledging security forces; the group has killed hundreds of people this year.