Most of the victims were students of an Islamic school in Paynesville, a city near Monrovia, said Samuel Worzie, an assistant minister for information services and a government spokesperson.
Worzie told Xinhua that one of the instructors at the school was also found dead following the incident on Tuesday night.
"It is unfortunate. The fire wreaked havoc, killing up to 29 people," said Worzie.
Dozens of students were at the school at the time of the incident, and they were all asleep when the fire broke out at the building which served as a hostel and attached to a local mosque, he said.
Police spokesman Moses Carter told the media that the fire was caused by an electrical issue. Further investigations were underway, he said.
Liberian President George Weah also confirmed the accident on his Twitter account, expressing condolence to "the families of the children that died last night in Paynesville City, as a result of a deadly fire that engulfed their school building".
"This is a tough time for the families of the victims and all of Liberia. Deepest condolences go out to the bereaved," Weah said.
A rescue operation had been ongoing at the scene of the incident, with emergency workers conveying the victims in ambulances as of Wednesday afternoon, a witness told Xinhua.