An attack at the American University in Kabul ended after two attackers were killed, police said early on Thursday, nearly 10 hours after militants stormed the complex, prompting desperate pleas for help from trapped students.

The attack triggered explosions and gunfire, killing at least 12 people in an assault which comes just weeks after two university professors - an American and an Australian - were kidnapped at gunpoint near the school.

No group has so far claimed responsibility for the attack at the prestigious private university, but it comes as Taliban insurgents step up their summer fighting season against the Western-backed Kabul government.

"We have ended our clean-up operation. Two attackers were gunned down," Fraidoon Obaidi, chief of Kabul police's Criminal Investigation Department, told AFP without offering any details.

Abdul Rahman Rahimi, Kabul's police chief, said seven students, three policemen and two security guards were killed during the attack.

Students at the American University of Afghanistan had barricaded themselves into classrooms, huddled under desks and used social media to plead for help during the Wednesday evening assault.

Local media reported that hundreds of students had been rescued during the overnight operation.