An NYPD officer survived three bullets fired Thursday by a gunman, who then killed himself in the Brooklyn bedroom where he had opened fire, the police commissioner said.

The policeman was struck once in the right arm and twice on his bullet-resistant vest shortly after 4:35 p.m. while he was inside a Cypress Hills home on Ridgewood Avenue after answering a woman’s 911 call about her emotionally disturbed son, city officials said.

“The officer did not return fire,” said NYPD Commissioner James O’Neill. “Immediately after the shooting, the 29-year-old subject remained in the rear bedroom.”

The 30-year-old victim, a 75th Precinct officer on the job for two years, was rushed to Jamaica Hospital Medical Center, where he was “alert” and in stable condition Thursday night, officials said. His name was not released.

After a barricade situation in which authorities tried to reach the gunman to talk to him, emergency service officers burst into the bedroom and found the suspect had shot himself, police said. A semi-automatic weapon and a revolver were found by his side, police said. The suspect’s name was withheld pending notification of his family.

An NYPD officer was shot several times in Brooklyn on Thursday, Aug. 10, 2017, by a man who barricaded himself in a bedroom before killing himself, the NYPD said. Photo Credit: Theodore Parisienne

At the hospital, O’Neill called the wounded officer “brave” and held up his bullet-resistant vest during a news conference with Mayor Bill de Blasio and other city officials.

advertisement | advertise on newsday

“The right protective gear made all the difference,” the mayor said.

Police said the shooting began shortly after the woman’s call about her son, whom she said was not violent and unarmed.

The officer, accompanied by his partner and medics, went inside the house, but when the mother said her son might try to run out the back door, the partner went outside to monitor the rear, O’Neill said.

As the officer inside approached a rear bedroom, the suspect fired, police said. The officer was treated by the medics with him, police said.

An NYPD officer was shot several times in Brooklyn on Thursday, Aug. 10, 2017, by a man who barricaded himself in a bedroom before killing himself, the NYPD said.  Photo Credit: John Roca

That set off a tense stalemate as dozens of officers, including the wounded policeman’s colleagues, descended on Ridgewood Avenue.

Gawkers gathered by the orange tape warning people not to cross without a helmet and heavy duty vest. Police cars lined several streets in the neighborhood as helicopters circled overhead.

The mayor said he and O’Neill were in a meeting when they heard the news and were briefed before they rushed to the hospital to meet the officer.

“Thank goodness, the officer is gonna be fine,” the police commissioner said. “Recovery might take a while, but I saw the injuries, spoke to him, spoke to his partner, and they’re going to be fine.”

De Blasio said the wounded cop had a “great attitude” as he lay in his hospital bed and even made light of his situation.

“What could have been just another day, just another call turned into something much worse,” the mayor said. “Thank God our officer’s going to come through it. He’s a brave young man. . . . This is an example of the fact that our officers go into any situation and you never know how it might turn on a moment’s notice.”

advertisement | advertise on newsday

With Anthony M. DeStefano, Lauren Cook, Alison Fox, Pervaiz Shallwani