Mr. Wilson said he was in “total disbelief” when he first heard the news of the court’s ruling from another inmate who had heard it on the radio.

“It didn’t seem real,” Mr. Wilson said. “I stopped trying to figure the courts out.”

He got a laugh from reporters who asked where his welcome-home party would be.

“It’s not going to be any more parties for a while,” he said.

Mr. Wilson, who is black, was 17 when he was caught on videotape having oral sex with a 15-year-old girl at a drug- and alcohol-fueled New Year’s Eve party in 2003.

Mr. Wilson was convicted of aggravated child molestation for the act, a charge that carried a mandatory minimum prison term so harsh it shocked his jury and prompted an international outcry from critics who asserted that prosecutors had been overzealous and racially motivated. The law, critics said, was meant to keep child molesters behind bars, not to curb teenage sexual activity. The jury was not told of the mandatory sentence before it issued its verdict.

Image Genarlow Wilson was 17 years old in this photograph. Credit... Wilson Family Photo, via Associated Press

The year after Mr. Wilson was sentenced, the Georgia General Assembly changed the law to make consensual sex between teenagers a misdemeanor punishable by no more than a year in prison; but the legislature declined to apply the law retroactively to Mr. Wilson. That set up a test of wills between the lawmakers and judges, as Mr. Wilson’s lawyer appealed to both camps to free her client, who had been an honors student and star athlete.