Heavy gunfire and a series of explosions were heard in central Kabul late on Tuesday as Taliban fighters attacked a guesthouse popular with foreigners.
After a long gun battle, the four militants were killed by police. No other casualties were reported.
Teams of Afghan security forces were deployed at about 11pm local time to the Wazir Akbar Khan area, an upscale part of the capital where many embassies and government buildings are located.
More than a dozen explosions were heard in the first hour.
Most of the blasts sounded like rockets, but several more powerful detonations could have been suicide bombers, one Afghan security source said.
"We have surrounded the area and cornered them," Kabul police spokesman Ebadullah Karimi told AFP during the fight.
"The attackers wanted to get into Heetal Hotel but failed. They have now taken position among the trees behind the hotel and are firing at security forces."
The manager of the Heetal Hotel, owned by the family of Foreign Minister Salahuddin Rabbani and known for housing foreigners, said all guests were in safe rooms and no one was hurt.
"Heetal is very well fortified. After one or two initial explosions, our guards started firing on attackers who were unable to get inside," manager Beizhan told AFP by telephone from inside the guesthouse.
"Gunshots and blasts can still be heard from a distance," he added, without specifying if there were any foreign guests inside.
The guest house was damaged in 2009 when a suicide bomber blew himself up outside the gate, killing eight people and wounding another 40.
One witness said the attack began when a single shot rang out over the neighbourhood and didn't end until dawn.
The Telegraph's Afghan Franz J. Marty lives across the road from the compound that was attacked.
"[My landlord] saw a pick-up parked diagonally across the street with at least four attackers (16 to 17 years old only), wearing traditional Afghan clothes (no headscarfs or hats or anything), suicide vests and armed with AK 47s. They unloaded RPG rounds and IEDs."
Mr Marty, who took shelter in the basement of his building, counted at least 15 explosions.
The government later said the battle between police and the attackers ended with four militants killed.