MOGADISHU, Somalia — A truck bomb detonated outside a hotel in Mogadishu, Somalia’s capital, minutes before gunmen on foot stormed the building on Saturday afternoon, killing at least 23 people and wounding at least 30 others, the police reported.

Speaking to The Associated Press by telephone from the scene, Capt. Mohamed Hussein said 30 people, including a government minister, were rescued from the Nasa-Hablod hotel as heavy gunfire continued in the standoff between extremists and security forces. Three of the five attackers were killed, Mr. Hussein said.

The Nasa-Hablod hotel is frequented by government ministers, lawmakers and Somali business leaders.

The attack comes two weeks after a truck bomb left 358 people dead in the city.

The Shabab, an Al Qaeda-affiliated militant group, claimed responsibility for the attack on a media channel associated with the group.