It was the fifth deadly shooting by New York police in the last month.

The man, 29, was identified by family and neighbors as Victor Hernandez, a father of two who was the building’s superintendent.

Eight uniformed officers had responded to a call from a resident in the building who said someone had been banging on her door and breaking glass.

They were searching the second-floor hallway of 2785 Frederick Douglass Blvd. when one of the officers encountered a naked man armed with a 9 mm pistol, the police commissioner, James P. O’Neill, said.

“A violent struggle immediately began, and shots were fired,” the commissioner said.

The officer yelled for help as he struggled with the man and other officers opened fire, hitting him several times, mortally wounding him.

The officer who was grappling with the man was also hit, but his bulletproof vest stopped the slug, the commissioner said, noting that he had reviewed footage recorded on the officers’ body cameras.

The man was taken to Harlem Hospital Center, where he was pronounced dead. O’Neill said that he had been arrested and accused of domestic violence in the past. It was unclear if the man had fired his gun.

The resident who called police, Selina McNeal, identified the dead man as “Victor,” the superintendent.

McNeal said he had been yelling and screaming in the hall for about 20 minutes, making vulgar threats about a woman, before she called 911.

She said she briefly opened the door and saw the man. “He was butt-naked,” McNeal said. “But I didn’t see a gun. I saw something that looked like a laptop or a tablet.”

McNeal then shut the door. Minutes later, she said, police arrived, pouring out of the elevator. She heard a struggle and then officers yelling, “Shoot him! Shoot him! Shoot him!” Ten shots rang out in quick succession, she said. “Pop, pop, pop, pop.”

Then she heard officers shout, “Watch the fire.” Shortly afterward, she said she heard them yelling at one another, “Where is the gun?”

During the shooting, McNeal said, she was hiding under her bed in tears. After the confrontation ended, she again opened the door and saw the man lying on the floor face up. Police later told her that what she thought was a tablet was actually a gun.

“I’m still crying,” McNeal said. “I close my eyes and it’s all I can see and hear.”

The officer who was shot was also punched several times in the face and was being treated at a hospital, O’Neill said.

Hernandez was remembered by family members and neighbors as a kind, ambitious man who was close to his relatives and loved his children, a 6-year-old daughter and an older son.

His aunt, Ana Martinez, said Hernandez grew up in the Crotona Park East neighborhood of the Bronx. He had taken the police and fire exam and was studying at Bronx Community College, she said.

Hernandez’s ex-wife lived in Throgs Neck, also in the Bronx, Martinez said. The two had been fighting over custody of their children, and the domestic violence accusations stemmed from arguments between them, Martinez said.

Hernandez’s mother, Maria, had spent 19 years as a New York police officer, and he wanted to follow in her footsteps, according to Martinez. Hernandez also had relatives who were law enforcement officers in Milwaukee, Florida and Puerto Rico.

Given Hernandez’s ties to police, Martinez said, she doubted her nephew would have fired at police officers.

In a tribute posted to Facebook, Hernandez’s sister, Melissa, called her brother her best friend and protector, describing him as hardworking, creative and loving.

Hernandez “was always good at everything,” she wrote. He learned to play piano by ear, taught himself to make high-quality videos just months after buying a camera, and had strong technical and mechanical skills.

“My brother could do so many things, and it was always clear to me that he was destined for greatness,” wrote Hernandez’s sister, who declined to comment further. “Unfortunately, he’ll never get to use any of his many skills.”

Hours before the shooting, Victor Hernandez had dinner at a cousin’s house, Martinez said. He had also picked up his mother from the airport, where she had returned from a vacation in the Dominican Republic.

About 6 a.m. Wednesday, Martinez said she received a call from her sister, who was screaming, “They killed my son!”

Maria Hernandez declined to comment.

In Harlem, neighbors said they knew Victor Hernandez as a quiet man. Jerome Selassie, 55, who owns the corner store across the street from the site of the shooting, said he saw Hernandez often and never knew him to be violent.

“He was always polite, smiling,” Selassie said. “I saw him last night, at around midnight. He was running to his apartment because it was raining. He waved at me. That was the last time I saw him. He looked OK to me.”

The shooting took place across from the offices of Police Service Area 6, which serves several public housing developments in Harlem. Officers walking out of the building Wednesday shook their heads somberly and cautioned one another to “be safe.”

“It’s crazy that it happened right in front of the precinct,” said Fred Marshall, 44, who lives in the area.

He added: “Why do they always have to kill them, man? There are other things they could have done to put him down.”

The officer who was shot was taken to Mount Sinai St. Luke’s hospital, where he was in “good spirits” after the shooting, Mayor Bill de Blasio said at a news conference.

The officer, who has not yet been identified, is a seven-year veteran of the force whose wife is also a police officer. He is 32 years old.

He was released from the hospital in a wheelchair less than six hours after the shooting and was met from applause by fellow officers as he was escorted to a waiting police van.

Police have shot and killed five people since Sept. 29, when Officer Brian Mulkeen was killed in a police fusillade while struggling with an armed man in the Bronx.

On Oct. 15, in two separate encounters, officers fatally shot two armed men, one in the Gowanus Houses in Brooklyn and one at the 225th Street subway station in the Bronx. Two days later, also in the Bronx, a police sergeant shot and killed a man during a traffic stop.

Mulkeen was the second officer to be killed by “friendly fire” this year. In February, Detective Brian Simonsen was hit in the chest and killed as he and other officers were firing at a robber in a cellphone store in Queens. The robber turned out to have a fake gun.

This article originally appeared in

.