No group immediately claimed responsibility for the attack, the latest to target Kabul. Both the Taliban and the Islamic State group often stage large-scale bombings in the city, targeting Afghan forces, government officials and minority Shiites.
The early morning blast also set two vehicles ablaze although it wasn't clear if the attack was carried out by a suicide bomber or a remotely detonated bomb, said Kabul police spokesman Ferdous Faramarz.
The casualty tolls were released by the Health Ministry spokesman, Dr. Wahidullah Mayar, who tweeted that "6 people have been martyred & 27 more wounded, as a result of today's explosion in Kabul. All the wounded patients were evacuated to our hospitals and have been receiving the required treatment."
The university compound houses several hostels where many students stay over the summer, attending classes and conducting research. The university is co-educational.
Though Friday is the start of the weekend in Afghanistan, Massoud, an economics professor at the university who like many Afghans uses only one name, said that several lawyers were taking their exams to become judges when the explosion occurred.
It wasn't immediately clear if the lawyers were the target. In recent months, at least two professors at Kabul University with alleged links to Afghanistan's Islamic State affiliate have been arrested, and last year the wall that surrounds the university was emblazoned with graffiti reading, "Long Live Daesh," the Arabic name for the Islamic State group.
A U.S. Department of Defense intelligence official told The Associated Press that the IS affiliate has stepped up efforts to recruit students from Kabul's universities, particularly those who are tech savvy, to expand the group's strength and reach. The official spoke on condition of anonymity because he wasn't authorized to talk to the media.
Taliban spokesman Zabihullah Mujahid said he was not aware of Taliban involvement in Friday's attack.
In a 2016 attack, 13 people were killed, mostly students, and more than 40 people were wounded when militants attacked the American University in Kabul. In that attack, a car bomb exploded outside the university gates, followed by a blistering, hours-long attack in which gunmen roamed through the compound shooting at students and teachers.