The firefight erupted near a training facility overseen by the National Security Directorate - Afghanistan's intelligence agency - with the gunmen holed up in a construction site near residential homes, an official at the scene said.
"Afghan security forces have cordoned off the area as the clashes are ongoing".
With parliamentary elections due on October 20, authorities had been bracing for more attacks in Kabul and other cities, but even so, the scale of the violence has come as a shock to a government facing bitter criticism over its handling of the war.
There was no immediate word on the number of casualties among civilians and security forces nor any immediate claim of responsibility, which comes a day after a suicide bombing in a Shi'ite area of Kabul killed 34 people and wounded 56 others. The remaining victims were taken to their villages to be buried there, said Gulam Hassan, the cousin of one of the victims.
Islamic State issued a statement claiming responsibility in a statement on its Amaq news agency. The students were teenagers, preparing for university entrance exams at the time of the attack. "Mounting civilian casualties show beyond any doubt that Afghanistan and, in particular, its capital, Kabul, are not safe".
The body of a man killed in a deadly suicide bombing, that targeted a training class in a private building in the Shiite neighbourhood of Dasht-i Barcha, is taken for burial, in western Kabul, Afghanistan, Wednesday, Aug. 15, 2018.
The United States and North Atlantic Treaty Organisation launched airstrikes and sent military advisers to aid Afghan forces as they fight for the city, just 120 kilometers (75 miles) from the Afghan capital with a population of some 270,000 people.
The detonation of the bomb sparked gunfire from some nearby guard posts, but officials say they don't believe the guards were shooting at any attackers, and that there's no sign there was anyone else involved.
India’s three-time prime minister Vajpayee dies at 93
All government offices, schools and colleges to remain shut across the state. My condolences to his family & all his admirers.
The group has been conducting blistering attacks on security forces across Afghanistan, including the massive, days-long onslaught on Ghazni during the past week.
"It's the fighting season and the Taliban will want to rack up victories before winter".
The UN has warned that as many as 150 civilians may have also been killed.
Afghan forces appear to have finally pushed Taliban fighters from the strategic provincial capital.
Just after 4pm, Minister of Interior Wais Barmak confirmed the attack had ended.
"They were facing severe shortages of food and drinking water as the power supply was also suspended two days ago", a Taliban commander, who declined to be identified, said by telephone.
Small pockets of the city began opening up to humanitarian aid Thursday, while partial mobile service returned after telecommunications infrastructure and government buildings were destroyed during the fighting.