A fire has killed 24 people, mostly teenagers, trapped behind barred windows and a blocked exit in an Islamic school dormitory on the outskirts of Malaysia’s capital, officials said.

Firefighters rushed to the scene after receiving a distress call at 5.41am local time 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. He said there were at least 24 bodies, 22 of them boys between 13 and 17, and two teachers.

Mr Singh said 14 other students and four teachers were rescued, with six of them take to hospital in critical condition. “We believe (they died of) suffocation…the bodies were totally burnt,” he said.

Forensic police officer investigates burnt windows at an Islamic religious school following a fire on the outskirts of Kuala LumpurForensic police officer investigates burnt windows at an Islamic religious school following a fire on the outskirts of Kuala Lumpur (Daniel Chan/AP)

The fire broke out near the door of the boys’ dormitory, trapping the victims as it was the only entrance and the windows are grilled, fire department senior official Abu Obaidat Mohamad Saithalimat said. He said the cause was believed to be a short-circuit.

A fire department official said the bodies were piled on top of each other, indicating a possible stampede as people tried to flee the fire. The official had earlier said 25 bodies were found, but the more recent tally of dead and injured matches the number of people thought to have resided there.

Mr Singh said police were still finalising the details and investigating the cause.

Local media showed pictures of blackened bunk beds frames in the burned dormitory. A resident known as Norhayati told a local television station that she saw the boys crying and screaming for help, and waving their hands out of the window when the fire broke.