The blaze started about midnight and gutted a dormitory and school building where students slept in Paynesville, on the outskirts of the Liberian capital, Monrovia, police spokesman Moses Carter said.
At least 26 young pupils and two teachers were killed, the president's office said. Carter said 27 students - between the ages of 10-20 - perished in the fire.
"The kids were learning the Quran when the fire broke out," he said.
The cause of the fire was under investigation.
Rescuers in white masks and surgical gloves carried the children's bodies in bags from the burned-out building as crowds of people and relatives crushed together outside.
Parents at the scene wailed and wept as police fought a surging crowd to make way for ambulances taking away the bodies.
Pastor Emmanuel Herbert from a nearby church told The Associated Press he and his congregation woke up to sounds of the fire and called for help.
"When I turned around to look the entire place was red. When I looked through the window, I saw the whole place blazing with fire," he said.
The fire was so strong there was no way to enter the buildings, the pastor said.
President George Weah visited the site in Paynesville.
"We are here to encourage parents of the victims to have strength because it is painful to lose your kids in this manner," Weah told reporters at the scene.
"We extend our sympathy to the bereaved families. We don't know the cause of the fire yet, but we will encourage our investigators to find how it happened."
The Liberian authorities are all too familiar with deadly fires, often caused by malfunctioning generators, though "not on this scale", said presidential spokesman Isaac Solo Kelgbeh.
The majority of Liberians are Christian but there is a sizeable minority of Muslims among the 4.5 million population.
Source: Al Jazeera