Kabul police spokesman Basir Mujahid said two police officers were injured but there were no civilian casualties
Militants storm Kabul spy training centre
Militants stormed an intelligence agency training centre in Kabul on Monday in an attack claimed by ISIL, triggering an intense gun battle with Afghan police.
Security forces battled the militants, besieged in a construction site at the National Directorate of Security (NDS), for hours before killing at least two attackers.
"They were well hidden in buildings under construction. We exploded their VBIED and killed two or three of them," a source with the NDS told AFP on condition of anonymity, referring to a car bomb that attackers brought to the scene.
Kabul police spokesman Basir Mujahid said two police officers were injured but there were no civilian casualties.
During the attack, roads to the area were closed and dozens of police and intelligence officers blocked access to the public.
AFP reporters, who were held more than a kilometre away from the scene, saw ambulances and reinforcements headed towards the site.
"I was going toward my school. It [the attack] happened suddenly … the police arrived in the area fast and blocked the roads, not allowing anyone to get to their homes," Naweed, a student, told AFP.
ISIL claimed responsibility for the attack through its propaganda arm.
"Two ISIL attackers raid the Afghan intelligence centre in Kabul," the extremists' Amaq outlet reported.
The Afghan capital in recent months has become one of the deadliest places in the war-torn country for civilians, as the resurgent Taliban and increasingly ISIL both step up their attacks on security installations and mosques.
Security in Kabul has been strengthened since May 31 when a massive truck bomb ripped through the city's diplomatic quarter, killing about 150 people and wounding around 400 — mostly civilians.
No group has officially claimed responsibility for that attack, which the government blamed on the Taliban-allied Haqqani Network.
Monday's attack represents another blow to beleaguered Afghan police and troops.
The Taliban have targeted military installations in recent months, including a spate of attacks in October that killed around 150 people.
Afghan forces, already beset by desertions and corruption, have seen casualties soar to what a US watchdog has described as "shockingly high" levels since NATO forces officially ended their combat mission in 2014 and began a training and support role.
Morale has been further eroded by long-running fears that the militants have insider help — everything from infiltrators in the ranks to corrupt Afghan forces selling equipment to the Taliban.
ISIL, which has expanded its presence in Afghanistan since it first appeared in the region in 2015, has also scaled up its attacks in Kabul, including those on the country's Shiite minority.
Last month a suicide attacker blew himself up outside a political gathering in Kabul, killing at least 14 people in an attack claimed by ISIL.