Candles arranged on the floor for a voodoo ceremony caused a five-alarm fire that ripped through a Brooklyn apartment building last week, killing a 64-year-old woman and injuring 20 firefighters, the FDNY said Friday.

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

A city official says the man was known in the neighborhood as a priest and the two were having sex when the fire started.

The official spoke on condition of anonymity because the investigation was ongoing. He said he did not know whether the sex was part of the ceremony.

Candles on the floor around a bed where the ceremony took place ignited bed linens and clothes on the floor, fire officials said. Instead of calling 911, the man began retrieving water from a bathroom sink in a futile effort to put it out, but the flames only grew.

According to Fire Commissioner Salvatore J. Cassano, the occupant then opened the door to the hallway, which "allowed fire to spread into the hallway."

"Hopefully others will learn from this tragedy," he said in a statement.

Nearly 50 families were left homeless, and a retired guidance counselor, Mary Feagin, died in the blaze, which took some seven hours to get under control.

Her body was found in the debris on the top floor of the building on East 29th Street. Earlier this week, fire officials said that a dispatching error had delayed getting help to the blaze.

Dispatchers had directed an engine company to the fire on East 29th Street, but it was already at another emergency, helping a police officer who had accidentally shot himself in the leg.

FDNY spokesman Jim Long said the delay lasted "over a minute,'' until dispatchers discovered the error and sent another engine to the apartment fire. Officials said high winds also intensified the blaze.

Fire engulfed the fourth, fifth and sixth floors, causing part of the roof and fourth floor to collapse.

The fire department said the investigation is ongoing; it was not immediately clear whether there would be charges.