NORRISTOWN, Pa. – Bill Cosby walked out of court a free man Saturday — not because he was cleared of sexual assault charges — but because a jury decided that it could not reach a verdict on charges that he drugged and molested a woman at his home outside Philadelphia in early 2004.

Montgomery County District Attorney Kevin Steele immediately announced he would retry the case against the legendary entertainer, and Judge Steven O’Neill said the trial would be within the next three or four months.

“We will evaluate and review our case. We will take a hard look at everything involved and then we will retry it,” Steele said at a news conference. He confirmed that the alleged victim, Andrea Constand, would testify again at the new trial. “She’s entitled to a verdict in this case,” said Steele. “We will press forward to try to get that done, to get justice done.”

Cosby, who turns 80 next month, was subdued and seemed almost dazed when O’Neill declared the mistrial. The Hollywood icon left the courtroom without comment after sitting in his chair at the defense table for several minutes, simply gazing outward. At one point, counselor Angela Agrusa patted him on the shoulder.

He remains free on bail pending the new trial.

It took 52 hours for the predominantly white jury of seven men and five women to decide that it could not decide the case. “We, the jury, are deadlocked on all counts,” said the note read by O’Neill on Saturday morning. Defense lawyer Brian McMonagle moved for a mistrial — as he has done at numerous points during five days of deliberations — but this time, O’Neill granted the request.

And so a trial that was probably the biggest celebrity prosecution since the murder trial of O.J. Simpson in 1995 has ended without a final outcome. Constand, a massage therapist now living in Canada, was in the courtroom for the mistrial and hugged other alleged victims when the proceeding ended.

The judge, meanwhile, assured the panel members — whose identities remain sealed by court order — that he appreciated their efforts throughout the two-week trial.

“I will forever hold you dear in my heart and be grateful for what you have done for the justice system,” the judge told the jurors, who were selected last month in Pittsburgh and have been sequestered here since the trial began June 5.

He added that jurors should be proud of how they handled the case even though they could not reach a unanimous verdict. “Do not in any way feel that you have let the justice system down,” the judge told them.

Cosby was charged with three counts of aggravated indecent assault, all focusing on the alleged assault of Andrea Constand, 44, who was then manager of the women’s basketball team at Temple University, where Cosby was a member of the board of trustees. The criminal complaint was filed in December 2015, just days before Pennsylvania’s 12-year statute of limitations was due to expire.

The entertainer, who had an endearing reputation as “America’s Dad” from his years as the lovable Cliff Huxtable on “The Cosby Show,” faces up to ten years in prison on each of the three counts.

Constand is just one of dozens of women who have accused Cosby of giving them pills and then sexually assaulting them but she is the only woman whose alleged assault became the focus of criminal charges. The lack of a verdict left some of those other women, who have attended the trial, a bit dejected, but they and women’s right lawyer Gloria Allred pledged to continue to seek justice.

“It’s extremely emotional,” said Jewel Allison, a New York woman who has said that Cosby assaulted her, as she prepared to leave the courthouse.

Allred said she believes that justice will prevail. “It’s too early to celebrate, Mr. Cosby. Round Two may be just around the corner,” she said at a news conference outside the Montgomery County Courthouse.

The verdict came five days after spirited closing arguments in which Cosby was alternately portrayed as a man so intent on having sex with Constand that he used drugs to render her incapacitated, and as a man who had been framed by Constand and others in hopes of reaping monetary settlements in civil suits.

The alleged assault that sparked the charges took place in early 2004 after Cosby invited Constand to his home in Elkins Park, just outside Philadelphia, to discuss her career plans. Constand testified that she was planning to leave her job at Temple and embark on a new career plan and had been feeling stressed.

She said that Cosby brought her three blue pills, saying they would help her relax and assuring her they were safe. Reluctantly, she said, she took the pills because she trusted him as a friend and mentor, but soon, she felt whoozy and had blurry vision. She testified the entertainer led her to a couch and she quickly became incapacitated as Cosby groped her breasts, inserted his finger in her and put her hand on his penis.

“I was frozen,” she told the jury last week. “I wanted it to stop.”

Agrusa, in a painstaking cross-examination, sought to portray Constand as a woman who had changed her story so often she should not be believed.

For the last two weeks, the plaza outside the courthouse in this economically challenged county seat has been the staging area for media organizations from around the nation and Canada, and more than 100 journalists have been covering the trial and scores of members of the public, including some of the women who have accused Cosby of assaulting them, have attended.

Cosby, who has been described as legally blind, has been supported by longtime friends and a few actors, including Keisha Knight Pulliam, who played Cosby’s TV daughter, Rudy, on “The Cosby Show,” which remained popular as the show continued to be shown as reruns long after the TV series ended in 1992. His wife, Camille, was in the courtroom briefly when the defense rested its case.

The hung jury outcome was not unexpected. On Thursday, after about 30 hours of deliberations, said it was deadlocked on all three counts, but O’Neill directed the panel to resume discussions and try again to reach a verdict. On Friday, the jurors appeared to be doing just that. They asked a series of questions throughout the day, but on Saturday, shortly after they were to resume deliberations, it became clear that there would be no verdict.

O’Neill asked each juror if the impasse was impossible to resolve.

“Do you agree there is a hopeless deadlock that cannot be resolved by further deliberations?” he asked each juror. One by one, each one said yes.

Later, after the jury was out of the room, O’Neill said the trial was the “largest undertaking in probably the history of this county” and thanked public and the news media for their good behavior in the courtroom.

Both prosecution and the defense will likely take a hard look at how the case was presented. Steele said he and prosecutors Kristen Feden and M. Stewart Ryan “will evaluate and review” the case. “We will take a hard look at everything involved, and then we will retry it.”

Steele said it was important to resolve the case.

“This case is about a drug-facilitated sexual assault and it doesn’t matter what you look like or who you are. Our job is to follow the evidence where it takes us. We have done that,” said Steele.