At least 22 people have been killed by gunmen who stormed Kabul University before engaging security forces in an hours-long battle.
A spokesman for the Afghan interior ministry said the attack was eventually stopped when three gunmen were killed.
A regional Islamic State group claimed responsibility in a statement.
The attack began shortly before the expected arrival of government officials for an Iranian book fair and continued for several hours.
A further 22 people were wounded by the attackers.