A windswept, five-alarm fire that killed an elderly Brooklyn woman was started by candles placed on the floor near a bed while a man and woman were having sex after a voodoo ritual, sources said today.

Fire marshals determined that the Feb. 20 blaze at 346 East 29th St. in Flatbush escalated to a fifth alarm because of an open door and delays, but that it was all started by black magic.

“Time and time again we respond to tragedies that could have been so easily prevented,” said FDNY Commissioner Sal Cassano. “This fire had so many of those elements — candles left on the floor near combustible material, one of the occupants trying to douse the flames before calling 911 and an open door, which allowed fire to spread into the hallway. Hopefully others will learn from this tragedy.”

Retired guidance counselor Mary Feagin, 62, who lived on the sixth floor, died in the fire.

Fire Marshals said the blaze began around at 6:40 p.m., when a Brooklyn woman visited a fourth-floor apartment in the building, where she paid one of the male occupants $300 to perform a voodoo ceremony aimed at bringing her good luck.

After the ceremony, sources told The Post that the couple decided to have sex.

The fire was sparked after the couple knocked over the candles that were arranged on the floor around the bed, igniting the bed linens and clothes on the floor.

Instead of calling 911, sources said a second man who was also in the apartment “began retrieving water from a bathroom sink in a futile effort to put it out, but the flames only grew.”

As smoke began to gather in the apartment, the man then opened a window and propped open the door to the hallway in an attempt to dissipate the smoke.

Wind gusts of 40 mph “shot the flames back inside, creating a blowtorch effect as winds whipped in through the open window and pushed fire out into the hallway. The occupants fled the apartment, leaving the door open,” the FDNY said.

Fire engulfed the fourth, fifth and sixth floors, causing part of the roof and fourth floor to collapse. Nearly 200 firefighters took almost seven hours to bring the fire under control.