NEW YORK — The fire commissioner says a high-rise apartment fire blaze that killed a New York City fire lieutenant started in an air-conditioner electrical cord pinched between a bed frame and a wall.

Fire Commissioner Daniel Nigro said in a statement Sunday that the fire has been ruled accidental.

Lt. Gordon Ambelas died late Saturday after suffering multiple injuries while looking for possible victims in a burning apartment in Brooklyn. His was the Fire Department of New York’s first line-of-duty death in more than two years.

The fire broke out around 9:30 p.m. Saturday in an apartment on the 19th floor of a building in the Independence Towers complex, owned by the New York City Housing Authority. Flames spread to the 17th and 18th floors.

Firefighters solemnly hung flag bunting at the Brooklyn firehouse where Ambelas had worked for the last several months of his 14-year career.

“He died a hero – that’s how he lived,” firefighter Eric Bischoff said of his longtime colleague, friend and former roommate, calling Ambelas “truly one of the best human beings that anyone would ever want to meet.”

A light smell of smoke hung in the air outside the apartment building where the fire had burned as investigators went about their work and residents returned.

Steven Jimenez, 15, had been returning from a cookout to his ninth-floor apartment when he saw flames in a 19th-floor window. As he waited outside, he watched as a bandaged Ambelas was carried out, he said.

“It looked scary … and it was scary that it happened in my neighborhood,” said Jimenez, who ultimately spent the night at a friend’s home.

“Ambelas went into the apartment to search for life and did not come out, and by the time his brother firefighters found him, it was too late for him,” said Nigro.

Fellow firefighters found Ambelas unconscious and carried him out of the building. They worked with emergency rescuers to try to revive him, but he died at a hospital, Mayor Bill de Blasio said.

“New York City and the FDNY suffered a terrible and tragic loss,” he said.

Two other firefighters and two residents were treated for minor injuries.

The Housing Authority said in a statement Sunday that it was working with firefighters on the investigation; the agency didn’t answer questions about what fire prevention devices might have been in the apartment.

It is the department’s first line-of-duty death since Lt. Richard A. Nappi was killed fighting a Brooklyn warehouse blaze in April 2012.

A police officer, Dennis Guerra, died this April after he and his partner were overcome by smoke and carbon monoxide while responding to a mattress fire on the 13th floor of a Coney Island public housing complex.

Ambelas, a 40-year-old married father of two daughters from Staten Island, had been promoted to lieutenant 10 months ago. He was among the firefighters from Ladder 119 honored last month for helping to save a 7-year-old boy who became trapped in a roll-down gate in May. The boy was pulled 15 feet off the ground when his arm and head got stuck.

Ambelas said at the time that the incident “shows that FDNY members are always ready to help others. It was great teamwork all around.”

The boy is being raised in the neighborhood’s Satmar Hasidic Jewish community, and members of a local synagogue put up fliers Sunday mourning Ambelas’ death.

“The entire community’s heartbroken and saddened,” Rabbi Lieb Glanz said.