Richard Haste took a gamble — and lost. Now he is out of a job as an NYPD officer, without a badge, gun and pension.

Haste is the white officer who fatally shot unarmed black teen Rammarley Graham in the Bronx. He had been on modified duty since the 2012 shooting, but last week he resigned after a departmental trial found him guilty of poor tactical judgment.

Earlier, he had refused a sweet offer by then-Commissioner Bill Bratton to retire and keep his pension. He declined the offer because Bratton would not give him a “good guy” letter, police sources said.

The letter is given to officers who retire in good standing, and would have allowed Haste to obtain a pistol permit and keep his gun. Instead, Haste opted for a departmental trial, and a judge found him guilty and recommended his dismissal. He faces no criminal liability in Graham’s shooting, which has been cited in protests about policing and race.

In making his offer, Bratton apparently disregarded the wishes of Mayor Bill de Blasio, who, police sources have said, wanted Haste fired.

Bratton’s offer came in a meeting with Haste and three NYPD officials, including then-Chief of Department James O’Neill. It is unclear where O’Neill, who is now commissioner, stood on the offer. He was about to fire Haste, as the mayor apparently wanted, but Haste short-circuited him and resigned after the verdict.

As the mayor also wanted, O’Neill placed Sgt. Hugh Barry on modified assignment in October after he fatally shot Deborah Danner. The 66-year-old Bronx woman, who was black, was mentally disturbed, and police said she attacked Barry, who is white, with a baseball bat. At the time, O’Neill said: “We failed . . . We were called to that apartment to help someone. We ended up killing her.” Those words were in lockstep with de Blasio, who said, “Deborah Danner should be alive now. Period.” A Bronx grand jury is about to hear the case.

Of course, being the mayor’s man is standard operating procedure for commissioners who savor their jobs. Only Bratton has been the outlier. Just as he bucked de Blasio on Haste, he bucked Mayor Rudy Giuliani in 1994, taking credit for dramatic crime declines in NYC. Two years later, Giuliani forced him out.

Bratton’s successor, Howard Safir, so toed the Giuliani line that the mayor called him, “The greatest police commissioner in the history of the city.” Safir’s replacement, Bernard Kerik, paraded around the city in Giuliani’s back pocket after 9/11. Kerik’s successor, Ray Kelly, was allowed to rule the NYPD like a dictator, as Mayor Michael Bloomberg showed little interest in policing matters.

In one regard, O’Neill differs from his predecessors. He regularly appears at news conferences with the mayor’s wife, Chirlane McCray, whom police distrust even more than they do her husband. At a recent news conference on sex trafficking, which McCray and Councilwoman Vanessa Gibson attended, O’Neill kissed each woman on the cheek.

Can you see Bratton doing that? Or Safir? Or Kerik? Or Ray Kelly?