A raging fire has gutted an unoccupied residential building being used as a film set in New York City, leaving a firefighter dead.

The blaze broke out on the set of Motherless Brooklyn, directed by Edward Norton, at about 11pm local time on Thursday.

Flames poured out of the windows as firefighters swarmed the scene in Harlem, dumping water on the blaze to get it under control.

Firefighter Michael R Davidson was assigned to the nozzle and was to use the hoseline to suppress the rapidly spreading blaze.

Michael R Davidson (New York Fire Department via AP)
Michael R Davidson (New York Fire Department via AP)

He got separated from other firefighters inside the building as conditions deteriorated and had lost consciousness when he was found by fellow firefighters. He was pronounced dead at hospital.

“It’s an awful night,” Eric Phillips, a spokesman for mayor Bill de Blasio, said in a tweet.

“You haven’t heard a scream until you’ve heard the scream of a mother who’s seen her son give his life to protect us.”

Two other firefighters suffered burns and were in a serious condition and three others were injured, fire commissioner Daniel Nigro said.

“Our department and our entire city mourn this tragic loss of a very brave firefighter,” Mr Nigro said.

It is not clear what caused the blaze that ripped through the five-storey building.

It was home to the former St Nick’s Jazz Pub, a venerable bar that was closed in 2011.

The building was being used to film the adaptation of the Jonathan Lethem novel of the same name.

Norton was directing and starring, along with Bruce Willis, Willem Dafoe and Alec Baldwin.

Neighbours said the film crew had set up a sign that read King Rooster Jazz Club about two weeks ago.

Cars from the 1950s era lined the street.

“They started building the set two weeks ago and have been here every day,” Nathan Monroe-Yavneh, a neighbour, told the Daily News of New York.

Mr Davidson had been a firefighter for about 15 years.

He leaves behind a wife, Eileen, and four children – three daughters aged seven, three and one and a six-year-old son.

Local resident Daquan Evans, 28, told the New York Post he saw Norton at the scene, and he looked visibly shaken.

“That actor Ed Norton walked right by. He looked pretty upset,” Mr Evans said.

“This is crazy this fire. You think a movie comes up here and it is good for the neighbourhood. Not a fire . . . damn.”

Producers sent condolences to the family of the firefighter, according to a statement given to WABC.

They said crews immediately called the fire department when they noticed smoke on the set.

“We watched firsthand with astonishment as they charged into the smoke to make sure all were safely out and then fought to contain the blaze and prevent it from spreading, putting their lives on the line as they do every day,” the statement read.