Media playback is unsupported on your device Media caption The dormitory was gutted by the fire

At least 23 students and teachers have died in a fire at a religious school in Malaysia's capital, Kuala Lumpur.

The fire at the Tahfiz Darul Quran Ittifaqiyah broke out in the early hours of Thursday morning.

The victims are thought to been trapped in their dormitory as the windows were barred with metal grilles.

"It is one of the country's worst fire disasters in the past 20 years," Khirudin Drahman, director of the fire and rescue department, told AFP.

Initial counts put the death toll at 25, but police later revised that down by two.

Police said the dead were 21 students - all boys between the age of 13 and 17 - and two staff members.

Ten people were taken to hospital, and four are thought to have serious injuries.

Image copyright EPA Image caption Relatives of the victims arrived in the morning

The blaze was reported at around 05:40 local time on Thursday morning (21:40 GMT Wednesday). According to the police it began in the sleeping quarters.

In Islamic tahfiz schools - where children study the Koran - students often live at the school.

Images and videos circulating online showed the entire upper room of the school ablaze.

"Based on our initial investigations, the position the victims were found in indicated that they tried to escape through the windows but were stopped due to the fixed grilles on the windows," fire and rescue department operations deputy director Soiman Jahid said.

He said police were still investigating what caused the fire but that it likely was caused by short circuit or a lit mosquito repellent coil.

Local media report the school could have been operating against government regulations, because its fire safety permit application was allegedly still pending.

Malaysia's urban wellbeing and housing minister said there had been 29 fire incidents at tahfiz schools in the country since 2015.

Malaysian authorities have raised concerns about safety measures at unregulated private religious schools.

Earlier this year an 11-year-old schoolboy died in hospital after reportedly being beaten by a warden at a religious school.

Image copyright Reuters Image caption Picture from inside the school showed charred beds and scorched windows on the top floor

A neighbour living next door to the school told the Reuters news agency they heard screams and saw the flames.

"The children were crying for help, but I couldn't help them as the door was already on fire," he said.

One window appears not to have had metal bars, Reuters said, citing a 15-year-old student who described having seen eight children escaping through it and climbing down a water pipe.

Kuala Lumpur Police chief Amar Singh said the bodies were "totally burned".

"Unfortunately there was only one entrance, so they could not escape. All the bodies were found lumped on one another."

Image copyright Reuters Image caption Police chief Amar Singh said the victims probably suffocated due to the smoke

Officials said fire engines were at the site within minutes, and the blaze was put out within an hour.

Prime Minister Najib Razak tweeted his sympathies to those affected while a government minister said the incident should be quickly investigated "so that we will be able to prevent future disasters".

"We sympathise with the families. It is one of the worst fires involving so many lives in the capital in recent years, said Loga Bala Mohan, according to AFP.