A 3-year-old playing with a stove accidentally started the deadliest fire in New York City in more than 25 years, officials said Friday.

The flames spread quickly through a Bronx apartment building Thursday night, racing out the open door of the ground-floor apartment and up the stairwell, which the city’s fire chief said “acted like a chimney.” Five of the building’s residents were dead when the fire department arrived three minutes after the first 911 call.

By the time firefighters had extinguished the flames a few hours later, 12 people, including five children, had been killed, and four others were “fighting for their lives” in hospitals, New York City Fire Commissioner Daniel A. Nigro said Friday.

The youngest victim was Amora Vidal, a week shy of turning 8 months old, said her mother, Christine Batiz. Batiz, who lived in the building, was at work when the fire started just before 7 p.m.

Batiz wrote on a GoFundMe page that her mother, Maria Batiz, 57, called her at work to tell her that a fire had broken out in the building and she and the baby were trapped.

“I never heard from her again,” Christine Batiz wrote Friday. “Later on at around 1am i heard the news i never thought i would hear. I lost my angel baby and my bestfriend ; my mother.”

The fire started Thursday night around the time that many residents of the 25-unit, five-story building would have been eating dinner.

On the ground floor, a 3-year-old boy who Nigro said “had a history of playing with the burners and turning them on” was toying with the stove in his family’s kitchen. His mother discovered the fast-moving fire when she heard the child’s screams from another room. Grabbing her son and her 2-year-old, the woman quickly fled, leaving her apartment door open as she exited the building, Nigro told reporters Friday.

Soon, the flames were shooting up the open stairwell, trapping residents on the higher floors. As people panicked, fleeing into the halls and the fire escapes, the open doors and windows sucked the fire upward. “It took the fire so quickly upstairs that people had very little time to react,” Nigro said.

Some tried to flee down stairs that were consumed by flames and smoke. About 20 others had climbed onto fire escapes, with temperatures hovering in the teens, when the first firefighters arrived, he said.

The victims, he said, died from burns and smoke inhalation.

Esther Sakyi, 50, said she was alone in her bedroom when she felt the room getting hot. Not considering the possibility of a fire, Sakyi said she initially took off all of her clothes but then went to the door to see what was happening.

“I opened it, and the smoke just hit me,” she said.

Sakyi ran back through her apartment to the fire escape, still naked in the frigid night air. Firefighters, already on the scene, helped her into a ladder, and paramedics transported her to a hospital, where she received stitches for a cut sustained during the rescue.

It took 150 firefighters a few hours to extinguish the blaze.

“It was terrifying,” Sakyi said. “I am still in shock.”

December was the worst month for fire in New York City in a decade, Nigro said. And Thursday night’s blaze was New York City’s deadliest since 87 people were killed at a Bronx club in 1990. Ten died in a Bronx fire in 2007, nine of them children.

But Nigro said there was nothing unusual about the structure of the building that would have made it especially prone to such a disaster, a point that Mayor Bill de Blasio (D) reiterated later on WNYC radio.

“From what we know right now, there was not a problem with the building,” de Blasio said.

The building had more than 20 apartments with six open violations, however, including one for a defective smoke detector on the first floor, according to records of the city’s Department of Housing Preservation and Development.

Nigro said investigators had not determined how many of the building’s alarms were working at the time of the fire.

The building’s owner, Howard A. Alkoff, could not be reached for comment.

Nigro said it’s not rare for children to start fires.

“We get 75 to 100 referrals per year of children who are fascinated with fire, playing with fire,” he said.

“And also, you’ve seen the ads: close the door, close the door, close the door,” Nigro said. “If, unfortunately, you do have a fire in your apartment, then you must close the door when you exit because the results if you don’t are what happened here last night.”

Many of the 25 families who lived in the Bronx apartment building were immigrants, “hard-working people going about their lives,” said Jonathan Morris, the priest at nearby Our Lady of Mount Carmel Catholic Church, who said he spent Thursday night with the families at St. Barnabas Hospital as they were called upon to identify the dead.

They included Karen Francis, 37, her 2-year-old daughter, Kylie, and her 7-year-old daughter, Charmela. Francis’s niece, Shantay Young, 19, also perished. Francis’s mother told the New York Times that 13 members of the family lived in the building.

The American Red Cross set up an aid station for survivors at a high school, providing food, blankets and other support, including temporary housing, to the displaced. “It was horrific, heartbreaking,” said Michael de Vulpillieres, a Red Cross spokesman.

Investigators remained at the scene Friday afternoon, where firetrucks lined the street and pedestrian access was blocked. Fire department officials stood beneath a tent at the intersection, handing out fliers with information about kitchen safety and free smoke-detector installations.

Some neighborhood residents ventured by in the cold to offer donations and support.

“When I saw it on the news this morning, I started crying,” said Nancy Clark, a 42-year-old Bronx resident who came to the scene Friday to donate blankets, phone chargers and toiletries to displaced families. “You think of those kids [who were killed], and you just imagine what those families are going through.”