Malaysian Fire and Rescue personnel stand outside the Darul Quran Ittifaqiyah

Twenty-three people, mostly children, were killed Thursday when a blaze tore through a Malaysian religious school, trapped in their dormitory by metal grilles on the windows.

Pupils and teachers inside the Islamic study centre in downtown Kuala Lumpur screamed for help as neighbours looked on.

Many of the bodies of the victims -- who included 21 boys mostly in their teens -- were found piled on top of one another, indicating there may have been a stampede as the students sought to escape the blaze which erupted before dawn.

Firefighters rushed to the scene and the blaze was out within an hour but it wreaked terrible devastation. Pictures in local media showed ash-covered, fire-blackened beds in the students' sleeping quarters.

The accident will increase scrutiny of the religious schools known as tahfiz, where many Muslim Malays send their children to study the Koran but which are not regulated by education authorities and often operate illegally.

Norhayati Abdul Halim, who lives opposite the school, told AFP she heard screams as the morning call to prayer rang out.

"I thought there were people fighting," the 46-year-old said. "I opened the window to my house and I could see the school on fire -- they cried for help but I couldn't do anything."

By the time firefighters arrived at the Darul Quran Ittifaqiyah school in the heart of the capital, "the screams had stopped", she added.

Officials said that the children were unable to escape after the fire broke out, as the blaze blocked the only door to the top-floor dormitory and the windows were closed off with metal security grilles.

Fourteen students managed to get out, and seven are being treated in hospital.

"They escaped by breaking through a grille, and then jumping down, some of them came down holding onto (drain) pipes," said Health Minister S. Subramaniam.

Fire officials said they suspected the blaze -- one of the deadliest in Malaysia for two decades -- was caused by an electrical short circuit, or a mosquito repelling device.

- Controversial religious schools -

Subramaniam said the bodies of 21 students and two staff members had been recovered, revising down an earlier official death toll of 24 dead.

He said the bodies were being identified via DNA tests as they had been severely burned and it would take some time.

Nik Azlan Nik Abdul Kadir, who lost a 12-year-old in the fire, hugged his sobbing wife outside the school, and said he had seen his son only the previous evening.

"He was in a jovial mood -- he loved studying here," he told AFP, adding another of his sons had been "saved" as he had refused to attend the school for the past fortnight.

The accident added to mounting concerns about the religious study centres, particularly after officials said the school did not have the required licences to operate.

The centres were already under heightened scrutiny after an 11-year-old boy died after allegedly being beaten last year at one of the institutions in the southern state of Johor.

Local media reported that the fire and rescue department had recently raised concerns about fire safety measures at unregistered and private tahfiz, and had recorded 211 fires at the institutions since 2015.

The latest tragedy was "the consequence of the absence of enforcement, and the failure to abide by rules and regulations by the operators of the religious school", said Chandra Muzaffar, a political scientist who promotes Islamic reform.

Religious schools are not "above the law. One should close down schools which do not abide by the rules", he added.

More than 60 percent of Malaysia's population of about 30 million are Muslim Malay, and the country is also home to substantial ethnic Chinese and Indian minorities.