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."
A number of students were also reported to have been taken to hospital.
The cause is being investigated.
Local journalists have been sharing pictures online of distressed parents gathering outside the school.
Prime Minister Najib Razak has tweeted his sympathies to those affected.
Malaysian authorities have raised concerns about safety measures at unregulated private religious schools after a series of fires.
Local media report there have been more than 200 such fires since 2015.
This breaking news story is being updated and more details will be published shortly. Please refresh the page for the fullest version.