He never should have been out.

The career criminal and gangbanger accused of pumping a fatal bullet into the head of an NYPD cop Tuesday night dodged jail on a recent drug bust that could have landed him years behind bars — with the judge instead sending him to rehab, according to officials and records.

NYPD Commissioner Bill Bratton on Wednesday said suspect Tyrone Howard should never have been on the street.

“He is the poster boy for not being diverted,” Bratton told reporters, referring to a court program that allowed Howard to attend an outpatient drug treatment clinic for two years in exchange for not going to prison for dealing drugs last year.

Howard had more than 25 arrests under his belt at the time, including for drugs and assault.

“He’s been in and out of jail. You’ll probably have to talk to the district attorney’s office about why he’s out,” Bratton said, before clarifying that it’s a judge’s ultimate decision whether to place a suspect in a diversion program since the Rockefeller drug laws were amended in 2009.

Bratton said the killing of cop Randolph Holder, 33, was “a vivid and tragic reminder that there are some people that have to be in prison.”

Howard allegedly shot the plainclothes cop in the forehead at point-blank range in East Harlem after police responded to a report of a gang shootout in East Harlem.

“He’s the last person in New York City I would have wanted to see in the diversion program,” Bratton said of Howard, noting his long rap sheet and that he was wanted for an earlier shooting on Sept. 1.

That shooting took place on East 102nd Street, the same street where Tuesday night’s fatal confrontation began.

Manhattan Supreme Court Justice Patricia Nuñez signed off on the diversion program for Howard, sources said, although it was initially approved by another judge.

Nuñez last year tossed the evidence against two men charged with possessing 13 forged credit cards after the defense claimed they were racially profiled by the NYPD.

Referring to Howard, Bratton said, “There are some people who have to be in prison, and we have to work harder to make sure that they get to prison and they stay there. We seem to have the hardest time trying to keep them in jail or prison.

“If you use a firearm to shoot an individual, you should be in jail.”

About Holder, Bratton said, “He was mine. He was ours. But he was yours also.’’

Mayor Bill de Blasio offered condolences to the slain cop’s family and also to the NYPD — and echoed Bratton’s call that the criminal justice system needs to do a better job keeping hardened criminals behind bars.

“This is something we have to address in our criminal justice system. The perpetrator involved here is a hardened, violent criminal and should not have been on the streets.

“We have to ensure that an individual like this is not on our streets,” the mayor said. “People cannot be left loose to be hurting our police officers.”

Detectives had already been seeking Howard, 30, in connection with the Sept. 1 shooting in the 23rd Precinct where Holder worked, sources said.

Detectives have recovered an extended 30-clip magazine from the East River that they believe Howard tossed after the shooting, sources said.

They are still looking for the .40-caliber gun they believe he also used and threw in the river afterward, sources said.

Cops think he threw the murder weapon in the water because fishermen near the scene reported hearing a splash after the shooting, sources said.

When Howard was nabbed last night, he initially gave a fake name — Juan Gonzalez, a law enforcement source said.

The suspect was due in a Queens courtroom Wednesday after receiving a summons Aug. 29 for an open container of alcohol.

Howard has done two previous stints in state prison, according to corrections records.

He spent time upstate between Jan. 4, 2013, and April 23, 2014, for possession of a controlled substance. He had already been a state guest between May 4, 2007, and May 24, 2011, for sale of a controlled substance.

Holder was responding to a report of shots fired near 420 E. 102nd St. when he began chasing the suspect, who had stolen a bicycle at gunpoint, police said.

The suspect headed north on First Avenue before he got onto a foot bridge at 120th Street and crossed over the FDR Drive to the East River. That’s when he opened fire on Holder from just inches away, hitting him in the forehead.

Holder’s partner returned fire, hitting Howard in the leg and buttocks before he was arrested.

Additional reporting by Dana Sauchelli, Daniel Prendergast, Philip Messing, Bruce Golding and Rebecca Rosenberg