The ex-cop who broke open the NYPD corruption scandal narrowly dodged a prison sentence Wednesday — but not before sobbing so hard a judge told him to sit down and collect himself.

“Just relax, take a moment,” Manhattan federal court judge Sidney Stein told Richard Ochetal, who wept openly as apologized to the citizens of New York for his role in a massive bribery scheme in which NYPD brass were lavished with gifts and cash in exchange for expediting hard-to-get gun licenses and other favors.

“Take a moment, you can use the tissues, breath slowly — why don’t you sit down,” Stein suggested as he gave the cop time-served and two years’ probation.

But Ochetal shook his head and continued to apologize for dishonoring law enforcement everywhere.

“I apologize for failing you all. I dishonored my name, I dishonored your name, I dishonored the badge, and I dishonored the oath I took to protect and trust,” he blubbered. “This was this biggest mistake of my life.”

Prosecutors said the 14-year-veteran turned himself over to authorities in 2016 and began confessing to the wide-ranging corruption, in which NYPD brass exchanged official power for favors — including a $60,000 junket to Las Vegas in the company of a prostitute — leading to sweeping arrests.

Ochetal later testified at the trial of former NYPD Deputy Inspector James Grant and City Hall fundraiser Jeremy Reichberg. Grant was acquitted, while Reichberg was convicted and sentenced to four years in prison.

Stein indicated Wednesday he’d initially planned to sentence the ex-cop to time behind bars, but had a change of heart during the proceeding.

“I was not intending to sentence you to probation,” the judge said. “I think it’s important an example be made of every police officer who violates the oath.”

“Yes you dishonored the badge, but you clearly have done what you can to make up for it,” added Stein. “I’m going to sentence you to time-served, I think that’s an appropriate sentence.”

In addition, Stein sentenced Ochetal to 320 hours of community service and ordered him to cough up a $15,000 fine — roughly the amount he made in bribes before turning himself in.

The judge said he wanted the ex-cop, who’s now working as a stagehand, to spend the community service either talking to new cops about his misdeeds or putting in time working as a stage-hand for a not-for-profit theater.

“This part of your life is over,” Stein said. “Good luck to you, sir.”

Ochetal declined comment through his attorney as he left court.