Perched on a federal witness stand eight months ago, Martin O’Malley told a jury it “would be nice” to avoid prison time by testifying about his role in the massive bribery scheme at the heart of Chicago’s red-light camera program.

He didn’t get his wish.

But U.S. District Judge Virginia Kendall still showed a significant amount of mercy Monday when she handed a six-month prison sentence to the 75-year-old military veteran. Last month, she handed a 10-year prison sentence to the man at the center of the scam — ex City Hall insider John Bills.

“This case could not have been prosecuted without your testimony,” Kendall told O’Malley.

O’Malley faced as many as five years in prison after admitting he passed $560,000 in cash bribes from Redflex Traffic Systems Inc. to Bills.

U.S. Attorney Zachary Fardon, who sought a significant punishment for Bills, asked only for home confinement Monday for O’Malley. He described O’Malley as “the bottom of the rung” among the conspirators in the case, a “sad and tragic bagman” of fragile health who has fought a 40-year battle to stay sober and immediately cooperated with federal investigators in the case.

When Chicago’s top federal prosecutor finished quoting letters of support written on O’Malley’s behalf — the traditional task of defense attorneys — Kendall looked at O’Malley’s lawyer and said, “maybe you don’t want to say anything.” Michael Gillespie chuckled but acknowledged that his client “should have said ‘no’” when he realized Bills had pulled him into a kickback scheme.

O’Malley later described his own actions as “deplorable.”

“I stand before you an admitted felon, guilty as charged,” O’Malley told the judge.

O’Malley met Bills at Alcoholics Anonymous in 2002, when O’Malley was down on his luck and in need of a job. Bills steered him to a $60,000-a-year job at Redflex, which promised to pay O’Malley thousands in bonuses and commissions. O’Malley soon learned that much of that money was meant for Bills, who had quietly helped the Arizona company cheat its way into Chicago’s red-light camera contract.

Former Redflex CEO Karen Finley testified in January that O’Malley seemed far from qualified or even “computer savvy,” when he was hired.

But she boiled it down for a jury this way: “He takes care of John. And John took care of Redflex.”

Finley is due to be sentenced Nov. 10.

O’Malley testified that he spent years passing cash to Bills in envelopes at Manny’s Deli or Schaller’s Pump. The feds say he and Bills sent coded emails to each other about the bribes, including one that referenced an “eight-page speed report” — a reference to an $8,000 bribe.

The so-called bagman also used his Redflex money to buy a $177,000 Arizona condo. It was used mostly by Bills, who parked his Mercedes there. However, O’Malley hung photos of his family in the condo to deceive investigators, according to the feds.

This is the third consecutive week that a defendant has faced sentencing in a federal courtroom for his role in a Chicago kickback scheme.

Bills was sentenced Aug. 29 to 10 years in prison. Then, on Thursday, a federal judge in Atlanta sentenced former LAZ Parking VP Felipe Oropesa to six months in prison for steering a Chicago parking meter contract to a preferred company in exchange for a $90,000 bribe.