The fire broke out in the early hours of the morning at the school in the Jalan Datuk Keramat area.
"The number of confirmed dead are 23 students and two wardens," Khirudin Drahman, director of the city's fire and rescue department, told the AFP news agency.
Their ages were not immediately clear.
Such schools - which children study the Koran - usually take children from between five and 18.
The official said this could be "one of the country's worst fire disaster in the past 20 years."