KABUL, Afghanistan — Several heavily armed attackers stormed one of the capital’s fortified premier hotels on Tuesday night, and sporadic shooting and at least two loud explosions were heard as Afghan security forces battled insurgents for hours afterward.

Coming within a week of President Obama’s announcement of troop withdrawals from Afghanistan, the attack underscored the still precarious nature of security, even in the capital, as the transfer of responsibility to Afghan forces is about to begin in several areas of the country, including Kabul.

In the early hours of Wednesday morning, three attackers on the roof of the Intercontinental Hotel were killed by NATO helicopters, a NATO spokesman said.