KUALA LUMPUR, Malaysia -- A fire that blocked the only exit to an Islamic school dormitory killed 23 people, mostly teenagers, on the outskirts of Malaysia's capital early Thursday, officials said. A government official said a wall separating the victims from a second exit "shouldn't have been there."

Firefighters and witnesses described scenes of horror - first of boys screaming for help behind barred windows as neighbors watched helplessly, and later of burned bodies huddled in a corner of the room. Teacher Arif Mawardy said he woke up to what he thought was a thunderstorm, only to realize it was the sound of people screaming.

Firefighters rushed to the scene after receiving a distress call at 5:41 a.m. and took an hour to put out the blaze, which started on the top floor of the three-story building, Kuala Lumpur police chief Amar Singh said.

Get Breaking News Delivered to Your Inbox

Singh revised the death toll, saying there were 23 charred bodies instead of 24 - 21 of them boys between 13 and 17, and two teachers.

Authorities work at religious school Darul Quran Ittifaqiyah after a fire broke out in Kuala Lumpur, Malaysia, Sept. 14, 2017. REUTERS

"We believe (they died of) suffocation ... the bodies were totally burnt," he said. Singh said 14 other students and four teachers were rescued.

Health Minister S. Subramaniam said six other students and a resident who went to help were hospitalized, with four of them in critical condition.

The fire broke out near the only door to the boys' dormitory, trapping the victims since the windows were barred, fire department senior official Abu Obaidat Mohamad Saithalimat said. He said the cause was believed to be an electrical short-circuit, though Singh said the investigation was continuing.

Another fire department official, Soiman Jahid, said firefighters heard shouts for help when they arrived at the school. He said they found 13 bodies huddled in a pile on the right corner of the dorm, another eight on the left corner of the dorm and one in the middle near the staircase.

The charred interior of the religious school Darul Quran Ittifaqiyah, after a fire broke out in Kuala Lumpur, Malaysia, is seen in a handout photo, Sept. 14, 2017. REUTERS/Fire & Rescue Department of Malaysia

Local media showed pictures of blackened bunk bed frames in the burned dormitory. A resident, Nurhayati Abdul Halim, told local media that she saw the boys crying and screaming for help when the fire broke.

"I saw their little hands out of the grilled windows; crying for help. ... I heard their screams and cries but I could not do anything. The fire was too strong for me to do anything," she said. She added that the school had been operating in the area for the past year.

Noh Omar, Malaysia's minister for urban well-being, housing and local government, said the school's original architectural plan included an open top floor that allowed access to two exit staircases. But he said a wall was built dividing that floor, leaving only one exit for the dorm.

"The wall shouldn't have been there," he said. He added that the school submitted an application for a fire safety permit that hadn't been approved.

Family members wait for news of their loved ones outside religious school Darul Quran Ittifaqiyah after a fire broke out in Kuala Lumpur, Malaysia, Sept. 14, 2017. REUTERS

The Darul Quran Ittifaqiyah is a private Islamic center, known as a "tahfiz" school, for Muslim children, mainly boys, to study and memorize the Quran.

An Islamic state religious official, who declined to be named as she isn't authorized to speak to the media, said the school isn't registered with the local Islamic council.

The Star newspaper said there were 519 tahfiz schools registered nationwide as of April, but many more are believed to be unregistered. Many such schools are exempt from state inspections.

The newspaper said the fire department had recorded 211 fires in such private Islamic centers since 2015. In August, 16 people fled a fire at a tahfiz school in northern Kedah state. Another tahfiz school was destroyed by a fire in May but no one was hurt.

The worst fire disaster occurred in 1989 when 27 female students at a private Islamic school in Kedah state died when fire gutted the school and eight wooden hostels.