Gunmen have attacked the American University of Kabul (AUAF) with gunfire and explosions heard inside the campus, an Afghan interior ministry official said.

The president of the American University in the Afghan capital confirmed a militant attack is under way on the campus.

"Several gunmen attacked the American University in Kabul and there are reports of gunfire and explosions," the official said. "They are inside the compound and there are foreign professors along with hundreds of students."

Ahmad Shaheer, a student at the university, told Reuters by telephone that he was trapped inside the university.

"We are stuck inside our classroom and there are bursts of gunfire," he said.

Photojournalist Massoud Hossaini sent a message on Twitter saying he was stuck inside the building, adding: "This may be my last tweets,"

A student told NBC News that he had just walked out of a class with friends when he heard gunfire and they started running toward the cafeteria.

A "massive explosion" threw them to the ground.

"We got up, and in the midst of dust... kept running to the back of the building and climbed the walls and jumped down on the street," he said.

He said he is in a taxi and on his way to hospital with injuries to his back and foot.

Police spokesman Sediq Sediqqi said police and intelligence agency personnel are at the campus, on the western outskirts of Kabul. He said police believe there is just one assailant.

The attack comes two weeks after two university staff were kidnapped from their car by unknown gunmen. Their whereabouts are still unknown.