The incident took place in Wazir Akbar Khan district home to several embassies and official buildings in capital city of Kabul on Tuesday. No civilian or military casualties were reported, BBC reported.
The attack lasted for six hours between the security forces and militants.
The Taliban militants were armed with a rocket propelled grenade launcher and other weapons, the interior ministry said.
"Four attackers who had one RPG launcher, three AK-47s and one grenade launcher were killed in Wazir Akbar Khan," deputy interior minister Mohammad Ayoub Salangi said on Twitter.
The four gunmen were killed before reaching their target, Kabul police Abdul Rahman Rahimi said.
Taliban militants aimed to target the Heetal guesthouse, that was attacked by the Taliban in December 2009. The guesthouse is now officially known as the Rabbani Guesthouse.