The judge's ruling, delivered from the bench, capped a marathon two-day proceeding that focused largely on Cosby's contention that his December arrest violated a 2005 decision by former District Attorney Bruce L. Castor Jr. not to charge him.
At the time, Castor said, he concluded there was insufficient evidence to prove Andrea Constand's claims that Cosby had drugged and assaulted her at his Cheltenham mansion a year earlier.
Testifying Tuesday, Castor maintained that his 2005 declaration not to prosecute was meant to help Constand. He testified that all the parties knew about the non-prosecution agreement, which he said stripped Cosby of his ability to plead the Fifth Amendment and paved the way for him to be deposed in Constand's civil suit.
James P. Schmitt, a lawyer who has advised Cosby for decades, testified Wednesday that he believed Castor gave the entertainer's criminal attorney, Walter M. Phillips, assurances that the agreement was an "irrevocable decision" that would bind the District Attorney's Office for years to come.
"A promise of a prosecutor - even an oral promise - is one that is absolute, 100 percent enforceable," Christopher Tayback, a member of the current defense team, told the judge Wednesday.
Kevin Steele, the current district attorney, who last summer helped revive the case, said any such deal, or the notion it would apply to future prosecutors, amounted to special treatment. "A secret agreement that permits a wealthy defendant to buy his way out of a criminal case isn't right," he argued.
Steele also challenged Castor's testimony, calling it "revisionist history." He noted that his predecessor's account changed more than once and questioned why the purported agreement was never put in writing.
The judge acknowledged the dispute amounted to uncharted legal waters. "This is a very unique situation," he said.
After leaving the charges intact, the judge also denied a motion by Cosby's lawyers to disqualify Steele and his office from prosecuting the case. The defense contended Steele violated attorney ethics rules last fall by using an implied promise to charge Cosby to win office in an election over Castor.
But even as he rejected their arguments, O'Neill offered a glimpse of another strategy Cosby's lawyers may consider in an attempt to blunt the charges. If the case gets to trial, he said, they could reintroduce the non-prosecution argument in a move to suppress Cosby's 2006 deposition, which Steele's office used to build the current case after portions of it were released last summer.
In it, Cosby acknowledged a sexual encounter with Constand, which he maintained was consensual. He also testified that he had previously acquired Quaaludes with the intent of using them in consensual sexual encounters with women.
Throughout the hearing, O'Neill repeatedly reminded both sides that they were not in court yet to try Constand's underlying sexual-assault allegations.
During hours on the witness stand Tuesday, Castor rattled off a list of reasons why he thought her credibility would not hold up in court. Chief among them, he said, were inconsistencies in Constand's statements and her decision to contact a lawyer before she reported her alleged assault to police.
Now 42 and living in Toronto, Constand sued Castor last fall, contending he has repeatedly undermined her credibility for his own political gain.
She did not attend the hearing, but her attorney Dolores Troiani took the stand for prosecutors, and didn't mince words.
"We had a district attorney in 2005 slamming a victim," she said, describing Castor's public statements during the investigation that the case was weak.
She also explained that Constand sought civil counsel because she had heard news reports about women who had legal run-ins with Cosby.
Troiani cited a 1997 incident in which the comedian, with FBI help, secretly recorded a woman who claimed she was his illegitimate daughter in an attempt to extort $40 million. The woman was later sentenced to prison.
After Constand confronted Cosby with her allegations in January 2005, the comedian's representatives called her and her mother and offered money, an educational trust, and a trip to Florida, Troiani told the court.
The Constands "never asked for any money - Mr. Cosby was the one who interjected money into the conversation," the lawyer testified. "We thought Cosby - because he had done it before - was setting Andrea up."
She told the court that during settlement negotiations on Constand's civil lawsuit the next year, Cosby's lawyers wanted Constand to promise never to cooperate with a criminal investigation of him. "I was adamant that would not occur," Troiani said.
Ultimately, Constand agreed only not to initiate any further investigation of her claims. But under the terms of her confidentiality agreement with Cosby, she was free to cooperate if law enforcement contacted her first.
Other details of their settlement agreement, including the amount Cosby paid Constand, have remained confidential.
In July, Troiani said, Steele came to her office and said he would like to reopen the case. Troiani asked for time to talk it over with Constand.
"My client was deeply hurt by the manner in which she was treated" during the first investigation, Troiani said. "And yes, I am passionate and still furious about it."