State Rep. La Shawn Ford always insisted that the felony charges against him were “ridiculous.”

As it turned out, he was apparently right.

On Monday he walked out of a Chicago courtroom smiling, with all 17 felony counts against him dismissed.

In a shocking deal with federal prosecutors, Ford pleaded guilty to a single misdemeanor charge of tax fraud that will allow him to remain in public office and likely keep him out of prison.

It is a rare and embarrassing climbdown for the U.S. Attorney’s office, which charged Ford in 2012 with 17 far more serious felony counts connected to an alleged bank fraud.

From the start, the West Side Democrat, 41, has loudly protested his innocence, claiming the charges against him were motivated by race and his position as an elected official.

He adopted a humbler approach Monday after pleading guilty to a single count of delivering a false federal tax return and admitting to U.S. District Judge Rebecca Pallmeyer that he dodged around $3,700 in taxes by overstating the amount he spent to rehab a West Side home.

Carol Marin: Feds back off ruining a good man’s life

Apologizing for underestimating his taxes, he smiled broadly as he hugged his attorney, Thomas Durkin, telling him, “You took care of me and you saw me as a man, and I appreciate that.”

Ford — who invests in real estate through his business Ford Desired Real Estate, Inc — had originally been accused of fraudulently obtaining a $500,000 increase and a two-year extension on a line of credit from a failed bank called ShoreBank and making false statements to gain multiple advances.

The feds alleged in 2012 that he got the loans to rehabilitate specific buildings, used them for unrelated expenses, including, car loans, credit cards, mortgages, payments to a casino in Hammond, Ind., and even for his 2006 campaign for Illinois state representative.

All those charges are now gone, and though Ford faces a possible jail sentence of up to one year when he is sentenced in November, as a first-time offender he is far more likely to receive probation and a fine.

The surprise plea deal on Monday comes less than two months after Durkin in June accused prosecutors of unfairly targeting Ford because he is a black elected official — a charge they angrily rejected.

But evidence from a separate civil case showed that white defendants who engaged in identical behavior to Ford’s at ShoreBank were not criminally charged, Durkin argued in court papers at the time.

“There is no doubt that Defendant’s status as an African-American elected state public official drives this case,” Durkin wrote. “As counsel have argued in detail, but for his status as an African-American elected state public official, Defendant would not have been indicted.”

Though Pallmeyer refused to throw out the case on those grounds, it’s an argument that could have caused a political problem for prosecutors at trial.

U.S. Attorney spokesman Randall Samborn refused to comment Monday on why the feds agreed to such a good deal for Ford.

But outside court, Durkin said he was delighted.

“It’s a very, very favorable outcome,” Durkin said, as his client stood at his side.

“A lot of prosecutor’s offices would have been belligerent enough to insist on forcing the case to trial and run the risk of losing,” he said.

Asked if he thought Ford had initially been overcharged, he replied: “Look, I’m going to take my wins where I find them and I’m not going to gloat.”

The resolution of the case means that there is just one pending case against a politician in Chicago’s federal court, so often a graveyard for political careers.

Former State Rep. Keith Farnham, charged with possessing child pornography earlier this year, is the only politician who has been charged since Zach Fardon became U.S. Attorney in October.