Judge Thomas M. Durkin also ordered Hastert to undergo sex offender treatment, spend two years on supervised release after his time behind bars and pay a $250,000 fine to crime victims' fund.
In explaining his punishment, the judge called Hastert a "serial child molester."
Hastert becomes one of the highest ranking politicians in American history sentenced to prison. He pleaded guilty last fall to violating banking law as he sought to pay someone referred to in court papers only as "Individual A" $3.5 million to keep Hastert's sex abuse secret.
Earlier in the hearing, a former high school athlete who said he was molested by Hastert told the courtroom that he was "devastated" by the abuse.
The man, now in his 50s, said Hastert abused him while they were alone in a locker room. He struggled to hold back tears as he described the incident in detail. In the years since, he said, he has sought professional help and has had trouble sleeping. He said the memory still causes him suffering.
He said he trusted and looked up to Hastert.
Moments before the man took the stand, a woman who says her brother was sexually abused by Hastert told the courtroom that he felt "betrayed, ashamed and embarrassed."
Jolene Burdge said Hastert abused her brother, Stephen Reinboldt, throughout his years at Yorkville High School, where Hastert was a history teacher and coach from 1965 to 1981.
Reinboldt died of AIDS in 1995.
His sister turned toward Hastert and said, "Don't be a coward ... tell the truth."
She also said, "I hope I have been your worst nightmare."
In a statement to the court, Hastert said he was "deeply ashamed to be standing before you" and admitted that he "mistreated" some of the athletes he coached.
"I am sorry to those I hurt and misled," he said. "What I did was wrong and I regret it."
Authorities said Hastgert abused at least four students throughout his years at Yorkville High School, about 45 miles southwest of Chicago.
The 74-year-old, who was pushed into the courthouse in Chicago in a wheelchair, agreed to a plea deal that suggested anything from probation to a maximum of six months behind bars.
But after prosecutors lifted a veil of secrecy from the case, the judge made comments suggesting he might impose a longer sentence, potentially putting Hastert behind bars for years, because of the abuse allegations.
Defense attorneys are seeking probation on the grounds that Hastert has already paid a high price in disgrace. They also cite his health, saying a blood infection nearly killed him in November and that a stroke has limited his mobility.
The lead prosecutor said he wishes Hastert could have been charged with the sexual abuse he was trying to cover up.
Assistant U.S. Attorney Steven Block called Hastert's conduct "horrendous." But because of the statute of limitations, Hastert could only be charged with a financial crime related to the payments he was making to one of at least four victims of sexual abuse.
Block said the sentence should take into account that Hastert "continues to deny what should now be obvious to everyone," that the payments were to conceal sexual abuse.
Defense attorney Thomas Green said he "acknowledges and respects" the pain of the man who described being molested as a teenager. He urged the judge to take into consideration the "entire arc" of Hastert's life, asserting that he reshaped his life as a public servant during his political career.
"Decades of not just political achievement but acts of goodness and charity have been erased, a lot of it even physically as his name has been removed from public places and his portrait at the Capitol put into storage," Green said.
Some letters of support were withdrawn because the writers did not want to be identified, Green said, an example of Hastert's deepening isolation.
The maximum sentence available was five years in prison.
Until recently, it was hard to gauge what Durkin might be thinking. But at a recent hearing, he let his dismay show for the first time.
He singled out how Hastert in a 2015 interview with federal agents sought to deflect blame by falsely accusing Individual A of extorting him with a bogus sex-abuse claim. That lie would factor into the sentencing calculations, Durkin added: "That's a big one."
Earlier this month, prosecutors went into graphic detail about the sex-abuse allegations for the first time, even describing how Hastert would sit in a recliner chair in the locker room with a direct view of the showers.
The victims, prosecutors said, were boys between 14 and 17. Hastert was in his 20s and 30s.