A rookie cop working the most dangerous beat in the city killed a man in an unlit housing-project stairwell in Brooklyn — firing off an “accidental” shot that hit a young father in the chest, authorities said Friday.

“It was a pitch-black hallway,” Police Commissioner Bill Bratton said of the Thursday-night shooting at East New York’s Louis Pink Houses. “The deceased is a total innocent.”

Officer Peter Liang, 27, who was placed on modified duty while the NYPD’s Internal Affairs Bureau investigates, had set off with his partner, Shaun Landau, on a floor-by-floor sweep of the staircase at around 11:15 p.m.

They rode the elevator to the eighth floor and planned to walk up the stairs to the roof before descending to the lobby.

With his gun in his left hand and a flashlight in his right, Liang entered the stairwell at the same time Akai Gurley, 28, and his girlfriend, Melissa Butler, walked into the same stairwell on the seventh floor.

The stairs were dark because of a busted light that had been out for three weeks, and Liang was startled by the couple’s presence, sources said. He popped off one round, hitting Gurley in the chest from 10 to 12 feet away.

A mark on the stairwell wall indicates the bullet may have ricocheted before striking Gurley, police sources said.

The cops — who had spent less than 16 months on the job — retreated back to the eighth-floor hallway, as Gurley stumbled down to the fifth floor before collapsing on the concrete steps.

Butler knocked on the door of a neighbor, who called 911 and advised her how to administer first aid to the wounded Gurley.

“Lay him on his back,” the woman could be heard saying, according to sources. “Breathe into his mouth twice. Pinch his nose. Do chest compressions.”

By the end of the call, the scene was flooded with cops.

“There’s a lot of cops here,” the neighbor told the dispatcher, according to sources. “I think the cops shot him.”

Liang and his partner eventually headed down to the fifth floor to investigate, Bratton said.

The devastated officer later told cops it was an “accidental shooting,” a source said.

Butler was furious at the cops.

“They didn’t present themselves or nothing and shot him,” Butler told DNAinfo.com.

“As soon as he came in, the police opened the [door to the] eighth-floor staircase. They didn’t identify themselves at all. They just shot.”

Nyshae Dubarry, 25, who lives on the sixth floor, said she heard “a loud pow” and saw Gurley’s body in the building’s lobby a little while later.

“We saw his body on the stretcher. [EMS] were working on him in the elevator,” she said. “They were pushing his chest, but he was already dead. He didn’t move. He didn’t even blink. He had a hole in his chest. He only had his boxers on.”

Gurley, who has a 2-year-old daughter, was taken to Brookdale Hospital and pronounced dead on arrival, authorities said.

Butler, who had braided Gurley’s hair in her apartment before they headed out that night, was traumatized by the shooting, her mother told The Post.

“She keeps crying,” said Naomi Butler. “She’s very upset. She saw everything.

“Police shot him, and we don’t know why. He doesn’t carry any firearms. He was just going back home. They were taking the stairs. He’s a nice man.”

Bratton called the “accident” a tragedy and blamed it on the poorly lit stairwell.

“As the officers were entering the eighth-floor landing, the lights were not operable,” he said. “Everything points to accidental discharge.”

A neighbor on the eighth floor, Angela Tucker, said a broken light in that section of the stairwell had been neglected for three weeks and “with that door closed, you can’t even see in the staircase.”

A maintenance man was seen replacing the light on Friday morning.

Speaking at a Lehman College event in The Bronx, Mayor

de Blasio said Gurley’s shooting would be probed thoroughly.

“There’s going to be a full ­investigation, to say the least,” he said. “This is a tragic situation — that’s the bottom line. This is a tragedy. A life was lost, and my heart goes out to the family.”

De Blasio said Liang had been stripped of his gun and badge after being put on modified duty.

“On a very human level, we lost a life today,” the mayor concluded. “But it does appear to have been a very tragic accident.”

A law-enforcement source said “it doesn’t look good for” Liang, who is still within the probationary period as a rookie cop.

The civil-rights bureau of the Brooklyn District Attorney’s Office is investigating the shooting to decide whether to present the evidence to a grand jury.

Liang’s neighbor, Ronald Chan, 24, defended the cop’s actions and said he was as ­“always willing to help people.”

“It is dangerous,” he said of police work. “You never know what’s ­going to happen.”

Liang and his partner joined the force in July 2013 and had been part of a specialized overtime ­detail specifically assigned to the violence-plagued Pink Houses ­after a recent spate of crimes.

Gurley — who has a 2-year-old daughter and a young stepdaughter — lived in Red Hook with his domestic partner Kimberly Ballinger and the two girls.

Bratton, de Blasio, and the mayor’s wife Chirlane McCray visited the Red Hook home Friday night to hug and console Ballinger.

Additional reporting by Shawn Cohen, Natasha Velez, Ben ­Feuerherd, Yoav Gonen and Kirstan Conley