Dennis Guerra, the NYPD housing officer who died after being trapped in a Brooklyn fire, was remembered at his funeral Mass Monday as a man who put others first, a man with an understanding of duty and responsibility.

"Duty came first. It always did with Dennis," said Mayor Bill de Blasio to mourners at St. Rose of Lima Church in Far Rockaway.

Thousands of uniformed police officers and firefighters -- representing numerous departments -- attended the service, lining up outside the church in rows that stretched for blocks.

"Dennis gave it all -- all the time. He was a cop's son and a cop's cop," said Police Commissioner William Bratton.

Guerra, 38, a father of four, died early Wednesday of smoke inhalation and carbon monoxide poisoning after he and Officer Rosa Rodriguez, both of Queens, were overcome by dense smoke and toxic fumes in a Coney Island high-rise fire on April 6.

De Blasio, who attended with his wife, Chirlane McCray, told about how Guerra made time to help people devastated by superstorm Sandy -- even as his own family was hit hard by the storm.

"During those desperate days, Dennis regularly reported for duty well before dawn," the mayor said. "He climbed the cold, pitch-dark high-rise stairways of Red Hook houses with food and blankets and other essential supplies -- and with something else people badly needed at that moment: reassurance and a smile."

When it came time for Guerra to act, he never hesitated, de Blasio said, reminding mourners of the housing officer's ultimate sacrifice.

"Duty also came first eight days ago when, without a heartbeat's hesitation, he and officer Rosa Rodriguez did what so many wouldn't have had the courage to do."

Bratton also referred to Guerra's allegiance to duty and responsibility.

"No one dies in vain. Dennis did not die in vain," Bratton said.

Guerra leaves behind his wife, Cathy; and children Kathleen, 20, Jonathan, 17, Alyssa, 14, and Zachary, 7.

He was to be buried at St. John Cemetery in Middle Village.

His fellow officer Rodriguez, 36, is still hospitalized. She remains in critical but stable condition, according to The Associated Press.

Friday, charges were upgraded to felony murder against Marcell Dockery, 16, of Brooklyn, who police said started the mattress fire.

With Darran Simon and Gary Dymski