Bill Cosby was once known to millions as "America's Dad", but the comedian had his reputation shattered when he was sentenced to three to 10 years in jail after being convicted of sexual assault.
That judgement has now been overturned, and the 83-year-old has walked free from prison after serving two years of the sentence.
His role as the benevolent, jumper-wearing Dr Cliff Huxtable in 1980s hit sitcom The Cosby Show made him a national treasure in the US.
But more than a dozen women accused Mr Cosby of misconduct, and one case made it to court.
Although a jury failed to reach a verdict in June 2017, a retrial originally led to a conviction less than a year later. But in June 2021, Pennsylvania's highest court ruled he had been denied a fair trial, quashing the guilty verdict.
How did this man, a household name for so long in America, rise and fall so far?
How did his career begin?
Born in 1937 in a social housing complex in Philadelphia, the young William Henry Cosby Jr shone shoes and worked at a local supermarket to help his family make ends meet.
His early life was touched by tragedy when one of his four brothers died and he, the oldest, became a father figure.
Accounts of his school years portray a joker and a storyteller who loved to entertain classmates. After school he joined the US Navy, then went to university and worked part-time as a bartender.
Filling in for a club comedian, he laid the path for his future fame.
His debut on NBC's Tonight Show in 1963 led to a recording contract with Warner Brothers, and the release of a series of award-winning comedy albums.
On one of those, 1968's To Russell, My Brother, Whom I Slept With, he established the themes that would define his work - the father as a loving disciplinarian; siblings who could plot together one minute, then scream blue murder the next; and a confidence in the bonds of family.
The album sleeve noted: "During his time on stage, Cosby never once told a joke. He didn't sing or dance or do tricks. All he did was talk" - but the performer had the 10,000-strong audience in the palm of his hand throughout.
By the time the album was released, Mr Cosby was already a TV star.
What boundaries did Cosby break as a black actor?
In 1965, he had become the first black actor to star in a drama series, when he was cast in the espionage show I Spy.
He played Alexander Scott, an undercover agent posing as a tennis instructor, alongside Robert Culp, who played fellow agent Kelly Robinson.
Premiering during a time of great upheaval for race relations in the US, it was banned by some stations in the southern states. But Cosby went on to earn three consecutive best actor Emmys for his role - a record that still stands.
Despite his prominence on TV, Mr Cosby made a conscious decision not to directly address race relations in his act - preferring a more subtle challenge to the status quo.
"A white person listens to my act, and he laughs, and he thinks: 'Yeah, that's the way I see it, too,'" he once said.
"OK. He's white. I'm Negro. And we both see things the same way. That must mean that we are alike. Right? "So I figure this way, I'm doing as much for good race relations as the next guy."
The Cosby Show, which was launched by NBC in 1984 and aired for eight seasons, was his biggest success and established him as a household name.
Based on his stand-up routines, Mr Cosby's portrayal of an educated, affluent doctor - Heathcliff "Cliff" Huxtable - and the trials of raising five young children drew parallels with his own life.
His TV wife, Claire, was loosely based on his own wife Camille, whom he married in 1964.
The sitcom was watched by about 30 million viewers each week. By 1989, its star was earning $4m (£2.5m) a month in syndication rights alone.
When the show was cancelled in 1992, Mr Cosby embarked on a number of projects including film roles, but was never able to emulate the success of his star vehicle.
In 2013, he received rave reviews for his first TV stand-up show in 30 years, which led to a national tour.
But his comeback fell apart as several women came forward with allegations of sexual assault going back almost 30 years.
What were the allegations?
The accusations first surfaced in 2005, when Andrea Constand, a staff member at Cosby's former university, said she had been drugged and molested by the star at his home a year earlier.
Prosecutors declined to press charges, citing lack of evidence, but Ms Constand filed a civil case against the comedian.
Thirteen women, 12 of whom remained anonymous, agreed to be witnesses, each with a similar account of sexual assault.
Mr Cosby denied the accusations, which his lawyer called "preposterous", and the case was settled out of court in 2006 for an undisclosed sum.
In subsequent years, some of Ms Constand's fellow witnesses told their stories to the media. But the accusations were not comprehensively reported until Mr Cosby's planned TV comeback thrust him back into the limelight.
More than 50 women accused the star of sexual assault or rape, but due to time limits on cases, only one - Andrea Constand - took the case to criminal court.
Mr Cosby's lawyers consistently denied the charges, asking why the women had not made legal complaints at the time when they said they were assaulted.
In 2014 Mr Cosby said he had not addressed the allegations in public because "a guy doesn't have to answer to innuendos".
But shortly afterwards, previously unseen court papers from 2005 came to light and showed he had admitted obtaining sedatives to give to young women he wanted to have sex with. The sedatives, called Quaaludes, render people unable to move.
The accusations disrupted his hopes of a return to show business. Cable station TV Land pulled repeats of The Cosby Show, some of his stand-up shows were called off and protesters showed up to the ones that he still put on.
His statue was removed from the MGM Hollywood Studios park in Florida, and several colleges removed honorary degrees they had given him.
His portraits were taken down from the walls in his alma mater, Temple University in Philadelphia, and he resigned from the board of trustees.
What happened when the case came to criminal court?
At first, it appeared unlikely that any criminal action would be taken against Mr Cosby, partly because most US states have of statutes of limitation in cases of rape and sexual assault.
However, one case came to criminal trial - that of Andrea Constand.
The case was seen as one of the biggest US celebrity court case since the murder trial of former American football player OJ Simpson in 1995.
In June 2017, Ms Constand told her story in court for the first time, having previously been barred from doing so due to the 2006 settlement.
She said Mr Cosby had given her pills that he claimed were herbal and said would "take the edge off", but which left her virtually paralysed.
"In my head, I was trying to get my hands to move or my legs to move, but I was frozen", she said. About 20 minutes later, she said, he put his hand on her genitals.
"I wasn't able to fight it in any way," she told the court. "I wanted it to stop."
Mr Cosby continued to deny the allegations. He did not give evidence in court but had one witness. In the end, with Mr Cosby possibly facing the rest of his life in prison if found guilty, the jury was deadlocked, and a mistrial was declared in June 2017.
How was the retrial different?
The retrial, which began on 9 April 2018, took place in a changed atmosphere.
A flood of sexual misconduct accusations against powerful men in the entertainment industry such as Harvey Weinstein and Kevin Spacey had triggered the #MeToo movement.
The trial in Pennsylvania became one of the first celebrity cases of the #MeToo era. The decision by the judge to allow five more women to testify against him was seen as a key development.
On this occasion, the jury took two days to find the comedian guilty on all three counts of sexual assault. Months later, he was sentenced to a total of three to 10 years in prison.
Why was his conviction quashed?
After serving two years of the jail sentence, in June Pennsylvania's highest court overturned his conviction for sexual assault. Hours later, Mr Cosby was driven away from the prison.
The court found that Mr Cosby had been denied due process and should not have been put on trial because he had reached an agreement with the previous prosecutor in 2005 that he would not be charged.
"He must be discharged, and any future prosecution on these particular charges must be barred", it wrote in a 79-page ruling.
But despite the outcome, some legal analysts said Mr Cosby would not be able to go back to the life he knew before. His reputation would be "forever tarnished", said defence lawyer Rikki Klieman of CBS News.
"He does not go back to being America's Dad, everything that he lost in terms of the trappings of his life - his reputation, his TV jobs, his night club jobs, his being a spokesperson - all of that is gone."