Photos shared by a senior government official showed students lying dead in classrooms, some next to their books. One student appeared to have been shot as they were climbing out of a window.
“They were shooting at every student they saw … they even shot at the students who were running away,” witness Fathullah Moradi told Reuters.
The Taliban said their fighters were not involved in the assault. No other group immediately claimed responsibility.
Nineteen people were killed and 22 wounded before the security services ended the assault, interior ministry spokesman Tariq Arian said.
“This is the second attack on educational institutions in Kabul … Afghan children & youth need to feel safe going to school,” NATO Senior Civilian Representative to Afghanistan Stefano Pontecorvo said in a statement.
A suicide bomber killed 24 people including teenage students at an education centre in Kabul on Oct. 24. Islamic State claimed responsibility for that attack, without providing evidence.
Violence has plagued Afghanistan while government and Taliban negotiators have been meeting in Qatar to try to broker a peace deal and as the United States brings home its troops.