A bulletproof vest saved the life of a city cop Thursday after a gunman fired several shots at the officer, then killed himself after making a stand in his Brooklyn home, police said.

The Cypress Hills standoff unfolded on Ridgewood Ave. near Essex St. around 4:35 p.m., as officers responded to a call of an emotionally disturbed person barricaded inside a nearby building, sources said.

Cops and EMTs headed to the 29-year-old suspect’s apartment after his mother called police, reporting him as emotionally disturbed — but unarmed and nonviolent, NYPD Commissioner James O’Neill said.

An officer and medics entered the apartment and headed toward the rear bedroom, while a second cop circled around to a back door because the mom had warned police her son might try to slip out, O’Neill said.

“As the first officer approached the rear bedroom, the subject fired several shots, striking the officer several times,” O’Neill said.

Officer Hart Nguyen, 30, a father of two who joined the NYPD in July 2015, was hit twice in his vest and once in his arm, and is expected to survive, sources said. Medics took the cop to Jamaica Hospital, where he was awake and talking, police said.

“He had a great attitude. He was even trying to make light of the situation,” Mayor de Blasio said, speaking to reporters at the hospital Thursday night. “This young man was definitely saved by his vest.”

Police, none of whom fired a shot, were able to get the suspect’s mother out of the house and surrounded the building as state troopers and K9 units joined the stalemate.

When Emergency Services Unit officers entered the apartment later in the evening, they found the shooter, identified by sources as 29-year-old Andy Sookdeo, had shot himself to death.