Thirteen people, including seven students, died in an attack by gunmen on the American University in the Afghan capital Kabul, police say.
Two attackers were also shot dead by security forces nearly 10 hours after the assault began with an explosion on Wednesday evening.
Students and staff were trapped inside the university during the attack, which police said was now over.
No group has said it carried out the attack.
The victims also included three police and three guards. Thirty-five students and nine police were injured and about 750 students and staff were rescued, Kabul police chief Abdul Rahman Rahimi told the BBC.
Police had described the attack, which began at about 19:00 local time (14:30 GMT), as "complex". Special forces were on the scene along with American military advisers.
One of those trapped inside the university for several hours was Massoud Hossaini, a Pulitzer Prize-winning photojournalist, who tweeted his experience and pleaded for help.
He later managed to escape and told the Associated Press about the attack, which began with an explosion as he was in a classroom with 15 students.
"I went to the window to see what was going on, and I saw a person in normal clothes outside. He shot at me and shattered the glass," Mr Hossaini said, adding that he fell on the glass and cut his hands.
The students then barricaded themselves into the classroom. Mr Hossaini said at least two grenades were thrown into the classroom, wounding several classmates.
He and about nine students later managed to escape from the campus through an emergency gate.
"As we were running I saw someone lying on the ground face down, they looked like they had been shot in the back," he said.
Student Ahmad Mukhtar told the BBC that he was 100m away from the university's main entrance on his way home when he heard "six or 10" shots and a "huge" blast.
The explosion created so much light that it momentarily lit up the surrounding area, he said.
"I climbed a six-metre wall to escape," Ahmad said.
Other trapped students and staff tweeted or posted on Facebook their desperate pleas for help.
The attack comes two weeks after two university staff - one American, one Australian - were kidnapped by unknown gunmen. Their whereabouts remain unknown.
The American university, which first opened its doors to students in 2005, is a non-profit private university chartered in the US.
It offers English courses, adult professional qualifications and bachelor degree programmes, among others.
About 1700 students are enrolled; many are adults who study part-time and also have jobs.