In a surprise move, former Philadelphia Sheriff John Green pleaded guilty to felony conspiracy charges Tuesday, just days before his planned retrial on allegations he steered contracts worth more than $35 million to a campaign donor in exchange for more than $1 million in benefits over nine years.

“I am guilty,” the soft-spoken 71-year-old told U.S. District Judge Wendy Beetlestone in a hastily arranged hearing. “I have betrayed the confidence that the citizens of Philadelphia had in me.”

His abrupt about-face came a little more than a year after a trial in which Green denied those same allegations, and marshaled a defense that earned him acquittals on three of the five counts he faced and deadlocked the jury on the other two.

His lawyer, Peter J. Scuderi, said that with the retrial set to begin Monday, Green was not confident he could score a similar victory.

“The odds of that happening [once] in federal court are remote,” the lawyer said. “The odds of that happening twice are even more remote.”

Still, the last-minute nature of Tuesday’s hearing led to an unusual scene in court. Called before Beetlestone on short notice, Green was sworn in not in his usual suit, but in an untucked yellow polo shirt and slacks. Scuderi stood by him dressed in a windbreaker and khakis.

Under the deal they struck with prosecutors, the government agreed to drop one outstanding charge, cutting the maximum prison term Green will face from 10 years to five at his sentencing Aug. 1.

In exchange, Green agreed to forfeit just over $76,000 and admitted to a staggering array of corruption that stretched throughout much of his 22-year career in office.

A 17-year Philadelphia Police Department veteran, Green first won election in 1987 after an upstart campaign against the Democratic Party’s endorsed candidate. He kept that post for the next two decades, pledging to reform the office of 400 employees, whose duties include escorting prisoners to court and overseeing sales on foreclosed properties.

But in court Tuesday, Assistant U.S. Attorney Christopher Diviny detailed instance after instance in which one of Green’s chief supporters, James R. Davis, showered the sheriff with bribes — including hidden campaign donations, income for his wife, a newly renovated East Mount Airy home, and a no-interest $258,000 loan Green used to buy a retirement property near Kissimmee, Fla.

In exchange, Green essentially turned the non-law-enforcement functions of his office into a moneymaking operation for Davis. His companies — Reach Communications Specialists Inc. and a title company called RCS Searchers — were granted a virtual stranglehold over lucrative contracts to advertise and run sheriff’s sales.

City audits have shown that between 2002 and 2011, Davis’ businesses were paid hundreds of thousands of dollars per month for placing ads in local newspapers to promote the auctions and manage title transactions, with Davis earning a 15 percent commission.

In addition, Diviny said Tuesday, Reach added fees totaling $7 million that were not part of the initial deals. Green unquestioningly paid those bills, depleting the amount of money from the sale of each foreclosed home that went back to the owner.

Davis and his companies became so reliant upon Green’s largesse that when the sheriff considered retiring before his 2007 reelection campaign, Davis persuaded him to run again by offering to cover almost the entire cost of the campaign.

Green listed almost none of the $200,000 Davis contributed in donations, labor, and advertising costs on his mandatory campaign finance filings, nor did he report any other gifts Davis sent his way.

“John Green sold his office for an enormous stream of undisclosed and illegal benefits,” U.S. Attorney William M. McSwain said. “And for that, he should be deeply ashamed.”

Davis, 68, was tried alongside Green and convicted. He was sentenced to 10 years in prison last month and is scheduled to surrender to begin serving that term on Monday.

Green will remain free on bail until his sentencing later this year.