At a hearing, the jury said it could not reach a unanimous verdict on any of the counts being faced by the TV entertainer.
Cosby had been accused of sexually assaulting Andrea Constand at his Philadelphia mansion in 2004.
The jury had been deliberating for more than 50 hours on whether to convict the fallen TV star, but could not agree whether he had drugged and molested the 44-year-old.
Cosby’s wife Camille has condemned those who pursued the case – describing the district attorney as “heinously and exploitively ambitious”, and the judge as “overtly arrogant”.
Prosecutors have vowed to retry the 79-year-old, who is known for his long-running sitcom The Cosby Show.
Cosby had faced spending the rest of his life in prison if he was convicted on three counts of aggravated indecent assault.
Dozens of women have come forward with allegations, some dating back decades, but statutes of limitations mean those allegations are too old to reach court.
This had been the first criminal prosecution to be brought against Cosby, who will celebrate his 80th birthday next month with his legacy and reputation in shreds.
After the mistrial was declared, Cosby’s lawyer Angela Agrusa said: “This is what happens, juries are stuck when a prosecutor seeks to put someone in prison for things that are simply not presented in the courtroom.”
Dr Barbara Ziv, a forensic psychiatrist who has worked with victims of sexual assault, told Sky News: “When there are only two people involved there is always a ‘he said, she said’ element – so who are you going to believe?
“It’s hard to make judgements about credibility so there is a heavy reliance on physical evidence.”
Cosby does still face the possibility of civil trial on California over a claim dating back to the 1970s. Judy Huth says she was molested at the Playboy Mansion when she was 15 years old.
As with all of the allegations against him, Cosby has issued denials through his lawyers and remained largely silent himself.
Gloria Allred, a lawyer who represents many of his accusers, vowed: “We can never underestimate the blinding power of celebrity, but justice will come.”
Journalists who have investigated the star say it is not surprising that it took many years for allegations to surface.
Mark Ebner said: “They have been empowered because time in many ways takes care of time.
“Back then their livelihoods, their reputations, everything was on the line because they were helpless to do anything about it because they were smack up against this power.”
When the scandal erupted, he was embarking on a career comeback expected to cement his legacy.
Instead TV appearances were shelved, his star on Hollywood’s Walk of Fame was defaced and his live stand-up tour was dogged by controversy.