KABUL, Afghanistan — Four gunmen walked into an Afghan luxury hotel, proceeded to the restaurant and pulled out pistols hidden in their shoes.

They killed nine people, including a journalist for a French news agency, his wife and two children who were shot in the head. One child survived but was seriously wounded.

The Taliban boasted that Thursday night’s assault shows they can strike anywhere, and Afghan officials issued a string of conflicting statements as they scrambled to explain how the attackers penetrated the Serena Hotel’s tight security.

It was a major embarrassment to government security forces less than two weeks before national elections and came on the heels of an uptick in bombings and shootings against foreigners in the capital, something that had been relatively rare. A Swedish journalist was shot on the street earlier this month, and a Lebanese restaurant popular with foreigners was attacked by a suicide bomber and gunmen in January.

The latest attack was particularly brazen because it was considered one of the best-protected sites for civilians in Kabul, sheltered behind a nondescript wall. Entrants must pass through a security room at the gate, where they are patted down and go through a metal detector as bags are put through an X-ray machine and sometimes searched.

The attackers hid their small pistols and ammunition in their shoes and socks, Interior Ministry spokesman Sediq Sediqqi told reporters, but he could not say how the weapons went undetected. The hotel security has been known in the past not always to act when the metal detector beeps.