Taliban gunmen stormed a Kabul guesthouse used by a US-based aid group and held four foreigners hostage for several hours.

The attack came eight days before Afghanistan holds a presidential election which the militant group has vowed to derail.

Kabul is already on high alert and people across the country are on edge ahead of a 5 April vote the hardline Islamist movement has denounced as a Western-backed sham.

The siege of the walled compound, which is also home to a small church, lasted several hours before Afghan security forces killed the last remaining Taliban gunman holed up inside.

At least one Afghan child was killed when a suicide bomber blew himself up outside the building and the insurgents forced their way in. There were no foreign casualties.

About 20 people were evacuated from the guesthouse in an upmarket residential area of Kabul, many looking frightened and shocked.

A military spokesman said one of the attackers detonated a car loaded with explosives.

Three others blew themselves up inside the building and one was shot by security forces.

The country manager of Roots for Peace, which was using the guesthouse, said four people had been held hostage by the Taliban as their colleagues made frantic phone calls to establish whether they were alive.

Marie Harf, a spokeswoman for the US State Department, said there had been two US citizens in the guesthouse, and both were safe.

She said she did not know if they had been among those held hostage.

"We condemn this attack on Roots of Peace ... an organisation that only seeks to help Afghans improve their lives and their livelihoods," Ms Harf told a regular news briefing in Washington, adding that the organisation is supported by the US government.

"Again, the Taliban's actions demonstrate the growing distance between them and the Afghan people," Ms Harf said.

"A large majority of Afghans reject what the Taliban is trying to sell them. They reject this kind of violence and fear and intimidation and want to go to the polls."