An Afghan security personnel keeps watch near the Serena hotel, during an attack in Kabul March 20, 2014. REUTERS/Ahmad Masood

By Jessica Donati and Hamid Shalizi

KABUL (Reuters) - Taliban gunmen killed nine people, including four foreigners, in an attack on a luxury hotel used by U.N. staff and prominent Afghan politicians in Kabul on Thursday night, before being shot dead by security forces, witnesses and police said on Friday.

The assault on the heavily fortified Serena Hotel, which lasted some three hours, was the latest in a string of attacks by the insurgents seeking to spoil a presidential election on April 5, which would mark the first time in Afghanistan's history that one elected government hands power to another.

Four Taliban fighters snuck past security early on Thursday evening and hid inside the building for three hours before opening fire on diners inside the hotel's restaurant, according to interior ministry spokesman Sediq Sediqqi.

They then battled Afghan special forces as terrified guests hid in rooms or fled to hotel bunkers. All the Taliban gunmen were shot dead.

During the attack guests crouched in bathrooms with the lights turned off as they listened to gunfire and people running up and down the hallways.

"I never heard an explosion or anything. Only firearms and possible rocket-propelled grenades," one senior U.N. official said in a text message from his darkened room.

One of the hotel's main saferooms, which was packed with guests and Afghan members of parliament, filled with smoke from a fire in the kitchen. "It was hard to breathe. People started putting wet napkins on their faces," one witness said.

French news agency Agence France Presse said its Afghan reporter Sardar Ahmad, his wife and two young children were killed in the attack. The foreigners killed were from Canada, India, New Zealand and Pakistan, the interior ministry said.

All the 18 U.N. staff members known to be inside had been accounted for, according to a U.N. official.

SERENA HOTEL WAS SAFE HAVEN

Police are investigating how the gunmen got into the Serena. The hotel has dozens of armed guards patrolling its perimeter, and anyone entering is checked with metal detectors and body searched for weapons.

"Our first conclusion is that unfortunately that was a failure by that security and measures that were in place," Sediqqi said, showing reporters photos of pistols roughly the size of a packet of cigarettes and piles of ammunition.

Taliban spokesman Zabihullah Mujahid claimed responsibility for the attack and said the gunmen had targeted guests celebrating the eve of the Afghan new year on Friday.

"Suicide bombers have entered the Serena Hotel, heavy battle is underway, enemies suffered heavy casualties," the Taliban spokesman said in a text message.

The Serena hotel has been attacked several times during the Taliban insurgency, but Thursday's assault was the deadliest so far.

In 2008, gunmen disguised as police stormed the hotel and opened fire on guests inside its gym, killing six.

Despite its history as a targeted, the Serena's restaurant was one of the few places in Kabul where foreign officials were still permitted to dine, following a Taliban attack in January on a Lebanese restaurant that killed 21 people, including three U.N. staff and the International Monetary Fund's top representative in Afghanistan.

A U.N. spokesman told Reuters the attack would not stop the organization from providing support for the April election.

"This doesn't deter us from our commitment to assist the Afghan people and support them in the election," said Ari Gaitanis.

(Additional reporting by Katharine Houreld and Mirwais Harooni; Editing by Maria Golovnina and Andrew Roche, Simon Cameron-Moore and Michael Perry and Miral Fahmy)