An NYPD sergeant has been charged with murder for fatally shooting a 66-year-old, bat-wielding woman in the Bronx — the department’s first on-duty officer to be indicted for the rap since the death of Amadou Diallo in 1999.

Sgt. Hugh Barry, 31, was allowed to stand before Bronx Supreme Court Justice Robert Neary without handcuffs Wednesday afternoon, as his lawyer pleaded not guilty on his behalf to a single count of second-degree intentional murder, along with lesser charges of manslaughter and criminally negligent homicide.

Barry, who wore a black suit and a grim expression, was quickly freed on $100,000 bail. The NYPD had already suspended him shortly after he turned himself in at the courthouse Wednesday morning, pending the outcome of the charges, officials said.

Barry admittedly shot schizophrenic Deborah Danner in her apartment on Pugsley Avenue in Castle Hill in October after she threatened arriving cops, first with scissors, then a bat.

Barry was indicted despite taking the stand in his own defense before grand jurors last week and now faces a maximum sentence of 25 years to life in prison if convicted on the top murder count.

He is the first NYPD cop to be indicted on murder in an on-duty shooting since 1999, when four plainclothes Bronx cops were charged with fatally shooting Diallo, an unarmed Guinea immigrant. The four cops were acquitted at trial of all charges.

“In my view, this is stunning,” Barry’s lawyer, Andrew Quinn, told the judge during Wednesday’s brief arraignment.

“I have never seen an indictment … on this set of facts,” the lawyer said, calling Danner “an EDP [emotionally disturbed person] who by everyone’s agreement was armed with a deadly weapon.”

Barry’s prosecutor countered in court that in killing the paranoid woman, Barry “disregarded his training.”

“On October 18, 2016, Deborah Danner was a 66-year-old woman who was living by herself. … She had lived alone there for nearly 30 years,” Assistant District Attorney Wanda Perez-Maldonado told the judge in asking unsuccessfully that bail be set at $500,000.

Danner was a self-described “paranoid schizophrenic,” the prosecutor said. Cops had responded to her apartment in the past “without incident,” she said.

But at the point of rushing into the apartment that day, Barry “didn’t know who she was,” the prosecutor told the judge.

“When they arrived, Ms. Danner was inside her apartment by herself. … Her apartment door was closed. She did not want police in her home. She did not want to go to the hospital.

“She was in her nightgown alone in her apartment with scissors in her hand,” the prosecutor said.

In opening fire, “Barry disregarded his training from the New York City Police Department in dealing with emotionally disturbed persons … by rushing into Ms. Danner’s apartment without getting critical information.”

Barry has said through his union representatives that he opened fire in self-defense after Danner began to swing the bat at his head.

The shooting drew widespread attention the next morning, when Police Commissioner James O’Neill said of the incident, “We failed” — a declaration that still rankled officials in the NYPD’s Sergeants Benevolent Association on Wednesday.

“[O’Neill’s] reaction triggered the mayor to go on a 48-hour tirade, ultimately, I believe, impacting the jury pool here in the Bronx,” complained Ed Mullins, who heads the Sergeants Benevolent Association.

About 12 members of the union joined him in attending the arraignment.

“I firmly believe that as we go forward, that we will see Sgt. Barry will be vindicated, will be acquitted,” Mullins said.

“There’s no doubt he was following what any New York City police officer would have done [given] deadly physical force with a baseball bat. We’ve seen it. It’s taught in our training. He responded as he is required to do.”

Danner was notorious in her neighborhood for spitting, cursing and screaming “I’m going to kill you!” at those around her.

One of her outbursts, just a month before her death, sent FDNY trucks rushing to her apartment. Danner had threatened to turn on her stove and blow up her building, sources told The Post.

Still, Barry’s critics question why he drew his gun at all that day — and not the Taser he also carried.

“She was ill but not to be shot down and go to the grave,” Danner’s downstairs neighbor, Phillip Crowe, 77, said after learning of Barry’s indictment Wednesday.

“He knows it wasn’t necessary to kill that woman.”

Upstairs neighbor Valeriano Morrabal, 76, said, “He has got to pay for what he did. He made a mistake and now he’s got to pay.

“She was fragile,” Morrabal said, describing Danner as petite and thin. “He could have grabbed the bat. The very best decision would have been to Tase her.”

But Mullins has pointed out that Tasers, too, can kill. Just two weeks after Danner’s shooting, another cop from a neighboring precinct used a Taser to subdue a 49-year-old Bronx man who’d threatened arriving officers with a bottle. After two blasts from the stun gun, that man went into cardiac arrest and died.

“No one is talking about two weeks later, in the very same borough in the 45th Precinct, a Taser was deployed and a man was killed with the use of a Taser,” Mullins said.

“So we’re playing the what-if game. … And we can all second-guess what Barry did, but none of us were there in that room, none of us were there when it occurred, and none of us knew the deep history of Danner prior to this occurring, and neither did O’Neill.”

Barry will remain free on a bond posted by bondsman Ira Judelson pending his next day in court, July 7.

Additional reporting by Georgett Roberts and Laura Italiano