The punishment made him the first celebrity of the #MeToo era to be sent to prison and completed the dizzying, late-in-life fall from grace for the comedian, TV star and breaker of racial barriers.
"It is time for justice. Mr. Cosby, this has all circled back to you. The time has come," Montgomery County Judge Steven O'Neill said. He quoted from victim Andrea Constand's statement to the court, in which she said Cosby took her "beautiful, young spirit and crushed it."
Cosby declined the opportunity to speak before the sentence came down, and afterward sat laughing and chatting with his defense team. His wife of 54 years, Camille, was not in court. Constand smiled broadly upon hearing the punishment and was hugged by others in the courtroom.
In a blistering statement, Cosby spokesman Andrew Wyatt said the comic was subjected to "most racist and sexist trial in the history of the United States."
Among other things, Wyatt said all three of the psychologists who testified against Cosby were "white women who make money off of accusing black men of being sexual predators," and he accused prosecutors of using a doctored recording of a telephone conversation between Constand's mother and Cosby.
Cosby's lawyers asked that he be allowed to remain free on bail while he appeals his conviction, but the judge appeared incredulous over the request and ordered him locked up immediately, saying that "he could quite possibly be a danger to the community."
The comedian - who is legally blind and uses a cane - removed his watch, tie and jacket and walked out in a white dress shirt and red suspenders, his hands cuffed in front of him. He must serve the minimum of three years before becoming eligible for parole.
"For decades, the defendant has been able to hide his true self and hide his crimes using his fame and fortune. He's hidden behind a character created, Dr. Cliff Huxtable," Montgomery County District Attorney Kevin Steele said at a news conference, referring to Cosby's best-known role. But "now, finally, Bill Cosby has been unmasked, and we have seen the real man as he is headed off to prison."
Constand stood at Steele's side but shook her head to say she had no comment.
Former model Janice Dickinson, who was among the 60 or so women who have come forward to accuse Cosby of drugging and violating them over the past five decades, looked at him in the courtroom and said: "Here's the last laugh, pal."
Another accuser in the courtroom, Lili Bernard, said: "There is solace, absolutely. It is his fame and his fortune and his phony philanthropy that has allowed him to get away with impunity. Maybe this will send a message to other powerful perpetrators that they will be caught and punished."
The punishment, which also included a $25,000 fine, came at the end of a two-day hearing at which the judge declared Cosby a "sexually violent predator," a modern-day scarlet letter that subjects him to monthly counseling for the rest of his life and requires that neighbors and schools be notified of his whereabouts.
The comic once known as America's Dad for his role on the top-rated "Cosby Show" in the 1980s was convicted in April of violating Constand, Temple University women's basketball administrator, at his suburban Philadelphia mansion in 2004. It was the first celebrity trial of the #MeToo era.
Constand testified that Cosby gave her what she thought were herbal pills to ease stress, then penetrated her with his fingers as she lay immobilized on a couch. Cosby claimed the encounter was consensual, and his lawyers branded her a "con artist" who framed the comedian to get a big payday, a $3.4 million settlement she received over a decade ago.
Five other accusers took the stand at the trial as part of an effort by prosecutors to portray him as a predator.
Cosby faced anywhere from probation to 10 years in prison. His lawyers asked for house arrest, saying Cosby is too old and vulnerable to do time in prison. Prosecutors asked for five to 10 years behind bars, saying he could still pose a threat to women.
The sentencing came as another extraordinary #MeToo drama unfolded on Capitol Hill, where Supreme Court nominee Brett Kavanaugh stands accused of sexual misconduct more than three decades ago.
Sonia Ossorio, president of the National Organization for Women of New York, credited Cosby's accusers with helping pave the way for the #MeToo movement.
"Bill Cosby seeing the inside of a prison cell sends a strong message that predators - no matter who they are, from Hollywood to Wall Street to the Supreme Court - can no longer be protected at the expense of victims," she said.
The judge ruled on Cosby's "sexually violent predator" status after a psychologist for the state testified that the entertainer appears to have a mental disorder that gives him an uncontrollable urge to have sex with women without their consent.
Steele said Cosby could be sent to Laurel Highlands, a state prison for lower-risk inmates on the other side of the state, about 70 miles southeast of Pittsburgh. It serves inmates with special needs and has separate housing units for geriatric prisoners and programs for sex offenders.
In a statement submitted to the court and released Tuesday, Constand, 45, said that she has had to cope with years of anxiety and self-doubt. She said she now lives alone with her two dogs and has trouble trusting people.
"When the sexual assault happened, I was a young woman brimming with confidence and looking forward to a future bright with possibilities," she wrote in her five-page statement. "Now, almost 15 years later, I'm a middle-aged woman who's been stuck in a holding pattern for most of her adult life, unable to heal fully or to move forward."
She also wrote of Cosby: "We may never know the full extent of his double life as a sexual predator, but his decades-long reign of terror as a serial rapist is over."
The AP does not typically identify people who say they are victims of sexual assault unless they come forward publicly, which Constand and other accusers have done.
Constand went to police a year after waking up in a fog at Cosby's estate, her clothes askew, only to have the district attorney pass on the case. Another DA reopened the file a decade later and charged the TV star after stand-up comic Hannibal Buress' riff about Cosby being a rapist prompted other women to come forward and after a federal judge, acting on a request from The Associated Press, unsealed some of Cosby's startling, decade-old testimony in Constand's related civil suit.
In his testimony, Cosby described sexual encounters with a string of actresses, models and other young women and talked about obtaining quaaludes to give to those he wanted to sleep with.
Cosby's first trial in 2017 ended with a hung jury. He was convicted at a retrial that opened months after the #MeToo movement had taken down such figures as Hollywood studio boss Harvey Weinstein, NBC's Matt Lauer, actor Kevin Spacey and Sen. Al Franken.
Cosby, whose estimated fortune once topped $400 million, broke barriers in the 1960s as the first black actor to star in a network show, "I Spy." He went on to superstardom as wise and understanding Dr. Cliff Huxtable on "The Cosby Show," a sitcom that showed America a new kind of black TV family: a warm and loving household led by two professionals, one a lawyer, the other a doctor.
He also found success with his Saturday morning cartoon "Fat Albert," appeared in commercials for Jello-O pudding and became a public moralist, lecturing the black community about young people stealing things and wearing baggy pants. He won a Presidential Medal of Freedom and countless Emmys, Golden Globes and Grammy awards.
As the allegations mounted, his career all but collapsed, "Cosby Show" reruns were taken off the air, and one college after another stripped him of his honorary degrees.