Tariq Arian, the spokesman for the Interior Ministry, said that several gunmen had entered the campus, sending students fleeing.
He said security forces blocked the campus and shot the gunmen back at them.
In the attack, the Taliban denied involvement. In recent years, Afghan education centers have often been targeted by militants.
Mr. Arian said, "We don't know whether we're dealing with a coordinated attack or something else."
The AFP news agency was told by Hamid Obaidi, spokesman for the Ministry of Higher Education, that the attack began when government officials were expected to arrive for the fair's opening.
Video footage from the scene showed students, with the sound of gunfire in the background, walking and running away from the university. Some scaled walls in an attempt to flee.
Masooma Jafari, the health ministry's deputy spokeswoman, told AFP that four people had been taken to the hospital.
Last month, an attack by the Islamic State group outside a tuition center in Kabul left 24 people dead. The group also claimed responsibility in front of the university for a 2018 attack in which dozens were killed.
In recent months, violence in Afghanistan has worsened, even as the Taliban is conducting peace talks in Doha, Qatar, with the government. A senior UN official told the BBC last week that, despite assurances from Taliban officials to the US that it would sever ties with the terror group, al-Qaeda was still 'heavily embedded' within the Taliban.