At least 25 people, mostly students, were killed after a blaze broke out early on Thursday at a religious school in Kuala Lumpur - the deadliest fire in decades in Malaysia.

The fire at Darul Quran Ittifaqiyah - a "tahfiz" boarding school where students learn to memorise the Quran - was reported at 5:40am (21:40 GMT) Wednesday, according to a statement from the Malaysian Fire and Rescue Department.

Khirudin Drahman, director of Kuala Lumpur's fire and rescue department, told AFP news agency the number of confirmed dead is 23 students and two teachers.

"It really does not make sense for so many to die in the fire," he said. "I think it is one of the country's worst fire disasters in the past 20 years. We are now investigating the cause of the fire."

Seven people were taken to a nearby hospital for injuries, while 11 others were rescued.

Firefighters rushed to the scene, and the blaze was out within an hour, but not before it wreaked terrible devastation - pictures in local media showed ash-covered, fire-blackened beds.

Kuala Lumpur Police Chief Amar Singh told reporters the boys who died were aged 13-17, and that they probably suffocated due to smoke inhalation. The dormitory had only one entrance, leaving many of the victims trapped inside, he said.

An official said bodies were piled on top of each other, indicating a possible stampede as people tried to flee the fire. Some witnesses said they had heard the students crying for help after the fire broke out.

"They're still counting the bodies, which were piled on top of each other in a corner," Singh said.

Hundreds of people, including families of some victims, gathered outside the school as more bodies were being removed by fire officials.

The blaze began in the sleeping quarters on the top floor of the three-storey school building, fire officials said.

The police chief said no foul play was suspected. Abu Obaidat bin Mohamad Saithalimat, deputy director of the fire department, told reporters outside the school the fire was likely caused by an electrical short circuit.

Loga Bala Mohan, the government's federal territories deputy minister, said: "We sympathise with the families. It is one of the worst fires involving so many lives. We urgently want the authorities to quickly probe the cause of the deadly fire so that we will be able to prevent future disasters."

Tahfiz schools usually teach students between the ages of five and 18.

There were 519 tahfiz schools registered across the country as of April, but many more are believed to be operating unregistered. Such schools are unregulated by the education ministry and fall under the purview of the religious department.