Bruce L. Castor Jr. told a judge Tuesday that he couldn't remember every detail from his decade-old investigation of Bill Cosby, but on one point the former Montgomery County district attorney was certain:

His 2006 declaration that he would not pursue sex-assault charges on claims by a former Temple University employee amounted to a pledge that none of his successors would, either.

"Mr. Cosby was not getting prosecuted at all - ever - as far as I was concerned," Castor said. "My belief was that I had the power to make such a statement."

Castor was the sole witness in a daylong hearing as Cosby's lawyers mounted a bid to throw out a case they contend should never have been filed. For six hours in a packed Norristown courtroom, the former prosecutor parsed words, picked apart questions, and defended his decisions on the investigation.

Cosby's lawyers contend that the aggravated indecent assault charge filed in December against the 78-year-old entertainer violates a "non-prosecution" agreement Castor made with their client a decade ago. Prosecutors, led by current District Attorney Kevin Steele, say no such deal existed.

County Court Judge Steven T. O'Neill said he intended to rule when the hearing resumed Wednesday. He gave no indication of his plans, but spent several minutes peppering Castor with questions, including one that seemed to cut to the chase.

"Why," he asked Castor, "did you not make that agreement in writing?"

"It was unnecessary," Castor replied, "because I concluded that there was no way the case [against Cosby] would get any better."

The hearing marked the first major proceeding since Cosby's arrest, and drew an unprecedented media throng. The celebrity and longtime Temple University trustee arrived escorted by a personal security guard in a dark suit and wraparound sunglasses. Nearby, a small group of supporters called out.

"Hang in there, Bill," one yelled from the sidewalk.

Cosby waved back.

But from the moment the hearing opened, Cosby became almost a secondary figure, sitting quietly next to his lawyers. Castor was the center of attention.

A county employee for three decades, including two terms each as district attorney and county commissioner, Castor shook hands with deputies and kissed a bailiff on the cheek. He sat tall in his signature pinstripe suit and cowboy boots.

He kicked off his testimony with a 20-minute recitation of his career and the awards he has won. "There would be so many," he told the judge, it might be easier to submit a resumé.

After more than a year of media scrutiny, interviews, and criticism, the hearing was an opportunity for Castor, 54, to explain to a room packed with lawyers and reporters why he didn't arrest Cosby when Andrea Constand first alleged the comedian drugged and assaulted her in his Cheltenham mansion in January 2004.

"She had ruined her own credibility and would not be believed by a jury," he said. "That did not mean she was not telling the truth."

Castor said he had been troubled by the inconsistencies in Constand's 2005 statements to police, and by the fact that she had contacted a civil lawyer before reporting the alleged assault to authorities.

He also described several conversations he said Constand had with Cosby - over the phone and in person - that were problematic. Some had been secretly recorded, Castor said, a "possibly felonious" violation of Pennsylvania's wiretap laws.

"Her actions on her own - including going to a lawyer before going to police - had created a credibility issue for her that could never be improved upon," he testified. "I did not think there was any possibility that the case would get better."

Constand's attorney did not attend the hearing or respond to requests for comment Tuesday. Her client is suing Castor for defamation, claiming he undermined her credibility for his own political gain.

Castor said he met with Cosby's former criminal attorney, Walter M. Phillips, more than once during the first investigation. He said he informed Phillips, who died last year, of his decision not to prosecute Cosby.

But Castor testified that his 2005 decision had been mischaracterized - as if it was a negotiated or jointly approved deal.

"I keep seeing the word agreement," he said. "Everyone has used the word wrong."

Instead, Castor outlined what he described as a binding legal decision he reached on his own.

"I made a judgment as the sovereign representing the commonwealth not to prosecute Cosby," Castor said. "I was the only person in Pennsylvania who had the power to make that decision, and I made it."

Castor said he knew a civil suit was coming, and "set up the dominoes to fall in such a way that Mr. Cosby would be forced to testify."

Cosby's lawyers claim the comedian only agreed to sit for a deposition in a civil lawsuit Constand filed because he believed he would never be prosecuted. That lawsuit was settled out of court in 2006.

Transcripts of Cosby's previously confidential testimony, in which he describes his encounter with Constand and admits obtaining methaqualone to give to women with whom he hoped to have sex, were released last summer. The deposition became a factor in the decision to reopen the Montgomery County investigation last summer.

During cross-examination, Assistant District Attorney M. Stewart Ryan pushed to show Castor had contradicted himself in public statements, interviews, and emails.

Castor maintained he had been consistent and could explain everything. Much of his testimony focused on his choice of words and their meanings.

In one email last fall, Castor wrote, "if a prosecution could be made out without using what Cosby said . . . I believed then and continue to believe that a prosecution is not precluded."

Ryan asked how that was not a contradiction.

"If I was referring to the Constand case I would have written the prosecution," he said. "A prosecution refers to other victims."

The current case marks the first time Cosby has faced criminal charges despite similar allegations from dozens of women nationwide. If convicted, he faces up to 10 years in prison.

Despite the stakes, he showed little reaction throughout the day.

Castor, meanwhile, tried to dispel the notion that he was a witness for the defense.

"Let's be clear," he told defense lawyer Brian McMonagle at one point, "I am not on your team."

215-854-2608 @jeremyrroebuck

Staff writer Maria Panaritis contributed to this article.