CHICAGO (AP) — Former House Speaker Dennis Hastert has pleaded guilty in a hush-money case, in a deal with prosecutors that calls for him to serve zero to six months in prison and averting a trial in the case.

A judge, however, could go beyond that recommendation and give the former House speaker up to five years behind bars.

In exchange for the plea, prosecutors were expected to drop a charge that Hastert violated federal banking laws.

Hastert’s brief written statement was narrow, saying that he structured bank withdrawals in a way that they would not be detected.

The Illinois Republican explained why he lied to the FBI, saying simply, “I didn’t want them to know how I intended to spend the money.”

The judge asked Hastert, “Did you know that what you were doing was wrong?”

He responded, “Yes, sir.”

The change-of-plea hearing was the longtime GOP leader’s first court appearance since his arraignment in June, when he pleaded not guilty in the same courtroom in Chicago.

A May 28 indictment accused Hastert of handing as much as $100,000 in cash at a time to someone referred to only as “Individual A” to ensure past misconduct by Hastert against the person never became public.

The Associated Press and other media, citing anonymous sources, have reported that the payments were meant to conceal claims of sexual misconduct decades ago.

The plea helped seal the downfall of a man who rose from obscurity in rural Illinois to the nation’s third-highest political office.

Hastert was speaker for eight years — longer than any other Republican. He also parlayed his connections into a lucrative lobbying career after leaving Congress in 2007. That career is almost certainly over.

As a convicted felon, “no congressman will want to meet with him about anything. His influence and power will be gone,” said Dick Simpson, a co-author of “Corrupt Illinois: Patronage, Cronyism, and Criminality.”

Known as a savvy deal maker in Congress, Hastert and his attorneys negotiated the plea deal in recent weeks, avoiding a trial that could have divulged embarrassing secrets dating back to his days as a high-school wrestling coach.

Hastert allegedly made 15 withdrawals of $50,000 from 2010 to 2012. It’s what he allegedly did later in 2012 that would make his actions criminal. After learning withdrawals over $10,000 are flagged, he supposedly began taking out smaller increments, eventually withdrawing $952,000 from 2012 to 2014.

The withdrawals stopped after FBI agents questioned Hastert on Dec. 8, 2014, according to the indictment.

___

Associated Press writer Eric Tucker in Washington, D.C., contributed to this report.

___

Follow Michael Tarm on Twitter at http://twitter.com/mtarm

TPM staff contributed reporting.

Copyright 2015 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.