One of the cops trapped in a Brooklyn apartment building fire allegedly set by a bored teen died Wednesday morning sources said.

Officer Dennis Guerra had been declared brain dead and was on life support at Montefiore Hospital in the Bronx, where he was transferred after doctors struggled to stabilize him at Coney Island Hospital and Jacobi Hospital.

But the father of four was pronounced dead at 6:50 a.m., the sources said.

Mayor de Blasio on Wednesday praised Guerra as a selfless hero who was mortally injured while trying to help others.

“We lost a good man this morning. Officer Guerra was exemplary – he went to try to help people in need. Our hearts go out to the Guerra family – we will stand by them,” the mayor said.

And PBA president Patrick J. Lynch said he hoped other young people would learn the potentially tragic consequences of acting recklessly.

“We pray that every young person who hears of the tragic passing of hero police officer Dennis Guerra and of the suffering of officer Rosa Rodriguez and their families, learns that there deadly consequences that result from foolish actions,” Lynch said.

“We must learn from this tragedy so that their sacrifices will not have been made in vain. Our thoughts and prayers are with the Guerra and Rodriguez families, friends and their fellow officers.”

Family members had kept a vigil outside an intensive care unit in a hallway crawling with concerned cops and a police department chaplain before Guerra passed.

Guerra, 38, a married father of four, and his partner Rosa Rodriguez, 36, were the first two on the scene of a fire in a Coney Island apartment building, where they were immediately overcome by dense smoke as they stepped off a 13th-floor elevator and into a hallway where a mattress was set on fire.

Rodriguez was in critical condition at Cornell Medical Center’s burn unit in Manhattan where she was placed in a hyperbaric chamber.

After the accused arsonist, Marcell Dockery, 16, told investigators he was “bored,” according to sources, he was caught on camera with a wide grin as he was walked from a Brooklyn precinct, a gesture that outraged cops and Guerra’s heartbroken family.

“We saw him smiling on TV, is this a joke? We are going through so much right now,”Guerra’s mother Miriam said Tuesday outside her home before rushing off to the hospital as Guerra’s condition worsened.

“This is a very tough time for us. Because he was bored, two officers are now fighting for their lives, and one of them is my son,” she said.

Dockery — who set up an entire Facebook page devoted to his “obsession’’ with fire — was charged with felony arson and assault and reckless endangerment.

Mayor de Blasio and Police Commissioner Bill Bratton visited Guerra’s family at the hospital.

“The tragedy here is that a 16-year old young man would not have common sense enough to understand the implications of lighting a mattress, as has been alleged, on fire in his own building,” Bratton said before the hospital visit.

“How can any of us make any sense out of that?”

De Blasio saluted Guerra and Rodriguez for their bravery.

“We have such respect for what they have done for this city,” de Blasio said. “We feel for their families as they go through this terrible time, but we know that these two officers did what they did because people were in danger and they answered the call.”

City flags were lowered to half-staff to honor the son of a retired homicide detective.

A Far Rockaway neighbor fondly remembered Guerra’s kindness for clearing snow from the man’s sidewalk before he could get to it.

“He beat me to it,” the neighbor said. “He always managed to get my snow cleared for me.”

Mayor de Blasio said the whole city lost a good neighbor.

“We in New York City this morning are hurting,” de Blasio said. “We lost a good man.”

It surprised no one who knew Guerra that the gutsy housing cop would rush to the scene of a fire without a second thought.

“You always wanted him as your partner,” Borruso said.

How you can help his kids

New Yorkers can help the family of fallen Officer Dennis Guerra through the Silver Shield Foundation, which is collecting money that will go toward college expenses for his four children.

“This was a tragedy for everyone,” Silver Shield Foundation Chairman Billy Walters told The Post.

The foundation said it’s now paying tuition and other college fees for 65 children who lost a cop or firefighter parent in the line of duty.

Silver Shield has paid for the educations of 800 students since it was founded more than 30 years ago by late Yankees owner George Steinbrenner.

“We don’t want any of these kids to say, ‘My mom says I won’t be able to go to college because we don’t have the money,’ ” said Silver Shield board member Howard Lorber.

“So this helps, to not have that burden [of paying for college] or to have to think about it.”

Checks can be made out to Silver Shield Foundation, 870 United Nations Plaza, 1st floor, New York, NY 10017. Credit-card donations can be made at silvershieldfoundation.org.