The house had working smoke detectors that went off after the fire broke out, officials said.
Ayers said a neighbor reported seeing the boy and other children from the house playing with matches and sparklers the night before the fire.
"The neighbor told the grandmother they were playing with sparklers, that it was dangerous and somebody could get hurt," the commissioner said.
He said the death, the 32d in a fire in the city this year, underscored the need for adults to keep matches out of the reach of children.
And, he said, at this time of year, parents and guardians should not allow children to play with sparklers or illegal fireworks.
Ayers said the boy, whose mother is in Liberia, set the fire in the first floor rear of house and, apparently after failing to put it out, tried to flee by climbing a fire escape to the second floor, where he became trapped.
Firefighters found the child's body beneath a badly warped and melted aluminum door on the second-floor landing, he said.
Adults need to teach children that everyone should flee from a fire and not to attempt to extinguish it, Ayers said.
Two adjacent homes were damaged in the blaze, which was brought under control in about 30 minutes.
Contact staff writer Joseph Gambardello at 215-854-2153 or firstname.lastname@example.org.