The fire at the Tahfiz Darul Quran Ittifaqiyah broke out in the early hours, BBC reported.
A victim list released by the authorities showed 22 of the deceased were students while three others were religious teachers, Xinhua news agency reported.
Prime Minister Najib Razak tweeted his condolences. A Minister said the incident should be quickly investigated, the BBC report said.
Officials said fire engines were at the site within minutes, and the blaze was put out within an hour.
In Islamic tahfiz schools — where children study the Quran — students often live in the schools.
Images and videos circulating online showed the upper floor of the school, where students would have been sleeping, ablaze.
A number of students were also taken to the hospital, some suffering from smoke inhalation.
Videos posted on Twitter showed the three-story building was engulfed in raging fire before the fire fighters arrived, Xinhua reported.
The caused of the blaze is not yet clear.