A Brooklyn man who opened fire on an NYPD officer in 1997 was rearrested last week with a stash of guns and illegal drugs, but quickly released on $5,000 bail — and cops are fuming, sources told the Post.

“What was this judge thinking?” one irate Queens police officer told The Post of career criminal Stathos Hugunnie. “Stathos was arrested with three guns in the same projects where he tried to kill a cop. He shouldn’t [even] be released on $500,000 bail — obviously jail didn’t rehabilitate him.”

Hugunnie, then 21, fired multiple shots at officer Peter Bueti in April 1997 after police showed up at the door of his girlfriend’s apartment in the Queensbridge houses in Long Island City, according to police.

Hugunnie was wanted in connection with a double stabbing on the roof of the same NYCHA housing complex and fired eight shots at Bueti in a desperate bid to evade arrest — striking him three times in the chest, the New York Times reported.

The cop, who had been standing in the hallway, was saved thanks to his protective vest, officials said at the time.

Hugunnie was charged with attempted murder, assault, criminal weapons possession and criminal use of a firearm, and tossed in jail — but was released in 2017, sources said.

On Nov. 7 at 6 a.m., detectives from Queens North carried out a search warrant and found the would-be cop killer in another apartment in the Queensbridge Houses, loaded down with multiple firearms, ammunition, and grams of both heroin and crack cocaine, police said.

He was arrested and charged with criminal possession of a weapon and criminal possession of a controlled substance, and later released on $5,000 bail.

The apartment where Hugunnie, 43, was storing his stash belonged to his current girlfriend, Tywaneeka Norville, who was also arrested, sources said.

“Cops will continue to lock up perps like Hugunnie whenever they get caught with guns, but it will make no difference. Soon, they will be walking out the door before the ink on the arrest report is dry,” said PBA President Patrick J. Lynch in a statement.

“New Yorkers, this is your future, and the worst is still to come. The appalling and disturbing decisions that have now twice put a vicious cop-shooter back on our streets are not outliers — they are what our elected leaders have chosen.”