At least 20 people, mostly young women, have been killed in a bomb attack at an education centre in Afghanistan's capital Kabul where hundreds of students were preparing for university exams.

The bombing happened at the Kaaj Higher Educational Centre in the Dasht-e-Barchi neighbourhood of western Kabul, a predominantly Shiite Muslim area home to the minority Hazara community, which has been a target of some of Afghanistan's most deadly attacks historically.

Kabul police said 20 people were killed and 27 others wounded.

No group has yet claimed responsibility for the blast, however, the jihadist Islamic State (IS) group has claimed previous attacks in the area targeting girls, schools and mosques.

Italian NGO Emergency, which operates a hospital in Kabul, said it had received 22 patients, including 20 women, two of whom had died.

"The victims are all between 18 and 25 years old, and most of them were in the classroom to take an exam," it said in a statement.

The bomber shot dead two security guards before entering the gender-segregated classroom, student Ali Irfani, who managed to escape, told AFP.

"Not many boys were hit because they were at the rear end of the classroom. The bomber entered from the front door where girls were sitting," he said.

Akbar, another student witness, also told AFP that young women made up most of the casualties, with up to 600 people in the hall at the time.

A resident who brought victims to hospitals said he saw body parts scattered across the floor of the hall.

"Many students were hit by shrapnel in their head, neck and eyes," said Asadullah Jahangir.

The United Nations Assistance Mission in Afghanistan (UNAMA) told AFP that at least 24 people were killed and 36 others wounded in the attack, adding the numbers were expected to rise.

A neighbourhood shopkeeper said there was a loud explosion and then crowds of students rushed out of the centre.

"It was chaos as many students, boys and girls, tried to escape from the building. It was a horrific scene. Everyone was so scared," he told AFP, requesting anonymity.

'Shamefaced'

The Taliban's return to power in Afghanistan last year brought an end to a two-decade war and a significant reduction in violence, but security has begun to deteriorate in recent months.

The attack is a "shamefaced reminder of the ineptitude and utter failure of the Taliban, as de-facto authorities, to protect the people of Afghanistan", Samira Hamidi of rights group Amnesty International said in a statement.

The United Nations' special rapporteur on Afghanistan, Richard Bennett, condemned the attack.

"Onslaught on education for Hazaras & Shiites must end. Stop attacks on Afghanistan's future, stop international crimes," he said on Twitter.

Taliban fighters stand guard as people gather outside a hospital to search for relatives

Families rushed to hospitals where ambulances arrived with victims, and lists of those confirmed dead or wounded were posted on the walls.

"We didn't find her here," a distressed woman looking for her sister at one of the hospitals told AFP. "She was 19 years old."

Education is a flashpoint issue in Afghanistan, with the Taliban blocking many girls from returning to secondary education.

IS also stands against the education of women and girls.