The attack began on Wednesday evening with a large explosion from what officials said was a car bomb followed by gunfire, as suspected militants stormed into the complex where foreign staff and pupils were working.
It ended early on Thursday when two gunmen were shot dead by Afghan special forces who surrounded the walled compound and worked their way inside, interior ministry officials said.
The Afghan presidential palace said in a statement that seven students, three security force personnel, two security guards and one professor were killed in the attack, the second incident involving the university this month.
Islamist militant groups, mainly the Afghan Taliban and a local offshoot of Islamic State, have claimed a string of bomb attacks aimed at toppling the Western-backed government of President Ashraf Ghani.
But there was no claim of responsibility for the raid.
Ghani, in a statement, called the assault "a cowardly attempt" to hinder progress in Afghanistan. Such attacks would only strengthen the government's resolve to fight terror, he said.
The university said it was working with authorities to make sure everyone was accounted for.
Fraidoon Obaidi, chief of the Kabul police criminal investigation department, told Reuters that police had evacuated between 700 and 750 students from the university, which is popular with the children of Afghanistan's elite.
The Afghan presidential palace said initial findings by the intelligence services showed that the attack was planned in neighboring Pakistan. Afghanistan frequently accuses militants it says are in Pakistan for attacks on its soil.
Pakistan's army chief General Raheel Sharif spoke with the Afghan president, condemned the attack and pledged to cooperate fully with the Afghan investigation, Pakistan's military said.
A spokesman for the Pakistan government did not respond to a request for comment.
Authorities in Islamabad have long rejected accusations that Pakistan has provided support and sanctuary to militants who would attack Afghanistan.
The gunmen got into the building despite armed guards and watchtowers.
Students recounted barricading themselves in classrooms or jumping from windows to escape when the attack started.
"Many students jumped from the second floor, some broke their legs and some hurt their head trying to escape," Abdullah Fahimi, a student who escaped, told Reuters. He injured his ankle making the leap.
"We were in the class when we heard a loud explosion followed by gunfire. It was very close. Some students were crying, others were screaming," he said.
Others used an emergency exit, scaled walls and jumped to safety.
It was the second time this month that the university or its staff had been targeted.
Two teachers, an American and an Australian, were abducted at gunpoint from a road near the university on Aug. 7. They are still missing.
The American University of Afghanistan has about 1,700 students and advertises itself as the country's only not-for-profit, "non-partisan", co-educational university. It opened in 2006 and caters to full-time and part-time students.
Taliban insurgents control large swathes of Afghanistan, and the security forces are struggling to contain them, especially in the provinces of Helmand to the south and Kunduz to the north.
NATO ended its combat mission in December 2014 but thousands of foreign troops remain to train and assist Afghan forces, while several thousand other U.S. soldiers are engaged in a separate mission focusing on al Qaeda and Islamic State.
The United States said it was closely monitoring the situation in Kabul following the attack and that forces from the U.S.-led coalition were involved in the response in an advise-and-assist role.