On the street outside, the men’s boss, Minister of Telecommunications Shahzad Aryobee, was frustrated that the police would not let him get close to the building, which was partially in flames, as occasional explosions broke out. Mr. Aryobee tried to reach by phone the 105 staff members he said were inside to reassure them. “I’m here, I won’t leave you, help is coming,” he said.

There was little the minister could do but look on helplessly as the night wore on, with temperatures well below freezing, until morning came and authorities claimed they had retaken control of the hotel.

It was the latest in a series of serious attacks on the Afghan capital that have alarmed residents and undermined confidence in the government’s ability to cope with a worsening security situation.

There were fears of a much larger death toll, in part because similar attacks have proven more deadly. But in the morning, the security official said only five bodies had been found, with half of the building still uncleared.

However, officials indicated they did not have yet have full control of the hotel.

“Our special forces are entering the building,” said Gen. Afzal Aman, commander of the Kabul Garrison, an elite unit of police and soldiers that is responsible for security in the capital, who was reached by cellphone at the scene. “The attackers are at one side of the building. There are guests trapped in their rooms. We do not know who are the attackers.”

Hotels in Kabul have long been a favored target of various insurgents, and Saturday’s attack was the second time gunmen forced their way inside that hotel; in a 2011 attack, they went room to room, executing anyone they found.