The fire broke out at around 5.40 a.m. in a top-floor dormitory in the three-storey building, firemen said, where most of the students, aged between 13 and 17, were sleeping in bunk beds, with many of the windows covered by metal grills.
Two teachers were also killed in the fire at the Darul Quran Ittifaqiyah, a 15-minute drive from the iconic Petronas Twin Towers in Kuala Lumpur, police said. Most of the victims died from smoke inhalation.
The disaster has renewed calls for greater scrutiny of so-called "tahfiz" schools, where students learn to memorise the Quran. They are unregulated by the education ministry, being the responsibility of the religious department.
At least 30 fires at such schools have been reported this year, Urban Wellbeing, Housing and Local Government Minister Noh Omar told reporters, adding that the Kuala Lumpur school should not have been in operation. He did not elaborate on the previous fires.
Fire department operations deputy director Soiman Jahid said officials were investigating the fire but it was likely caused by a short circuit or a mosquito repellent coil.
The dormitory had only one entrance, leaving many of the victims trapped, he said. At least one window was unbarred.
"The building was surrounded by metal grills that could not be opened from the inside. The students, after realising the fire and heavy smoke, tried to escape through the window," Soiman said outside the school.
"But because of the grills, they could not escape."
Soiman said the school had submitted a request for fire safety approval but no new checks had been carried out as the request was still being processed.
"The pupils all got locked in and they couldn't escape and got burnt," Nadia Azalan, sister of a 13-year-old victim, told Reuters in tears as distraught family members gathered outside the building. "Safety should come first."
A man identified only as Hazin, who lived next door to the school, said his son called the fire department after they heard screams and saw the flames.
"I only managed to save a few of the kids who jumped out the window."
Mohd Izzarudin Roslan, 15, said he had broken a window and climbed out on to a water pipe.
Only eight of the boys managed to get out, he said.
"A few of my friends fell, there were some who had fire on their hair and clothes," he said in a video posted online by the New Straits Times, an English-language daily.
Viewed from outside, the only tell-tale signs of disaster were the blackened upper-floor windows, otherwise the tin-roofed building appeared unscathed, with a Malaysian flag hanging limply from the yellow wall.
Only inside did the intensity of the inferno become clear. The dormitory was blackened, lined with the charred frames of bunk beds.
Tahfiz schools have been under scrutiny since earlier this year when an 11-year-old boy died after reported abuse in Johor, north of Singapore.
(Additional reporting by Tavleen Tarrant and Joseph Sipalan; Editing by Praveen Menon and Nick Macfie)
(This story has not been edited by NDTV staff and is auto-generated from a syndicated feed.)
Get Breaking news, live coverage, and Latest News from India and around the world on NDTV.com. Catch all the Live TV action on NDTV 24x7 and NDTV India. Like us on Facebook or follow us on Twitter and Instagram for latest news and live news updates.