NORRISTOWN, Pa. — A bid by Bill Cosby's lawyers to have the sexual assault charges against the entertainer dismissed was rejected by a Philadelphia-area judge Wednesday, clearing the way for the famed comedian to be brought to trial.

Judge Steven O'Neill ruled that there was “no basis to grant the relief request” by the attorneys, after they argued over the previous two days that former Montgomery County District Attorney Bruce Castor had made a deal with the entertainer's lawyer years ago that Cosby wouldn't be prosecuted.

Castor testified that he had determined the criminal case against Cosby was weak and unlikely to succeed and that it would be better to have the comedian testify freely in a civil case filed by the plaintiff.

Present-day prosecutors scoffed at the argument and wondered whether Cosby had been allowed to “buy” his way out of facing criminal charges.

Cosby is facing three felony counts of aggravated indecent assault stemming from a 2004 interaction with former Temple University basketball staffer Andrea Constand.

Cosby is free on $1 million bail.

In another setback for the defense, the judge also denied a request to disqualify newly elected District Attorney Kevin Steele from the case. Cosby's lawyers had accused Steele of making a “political football” out of Cosby during the campaign.

During Wednesday testimony, lawyers for Constand painted Cosby as a hostile figure in past legal proceedings and called the district attorney who didn't prosecute him politically motivated.

“There was a lot of yelling and screaming and trying to divert our attention,” said Dolores Troiani, Constand's lawyer, of Cosby's behavior at the four-day deposition during the civil trial in 2005. “The first day he tried charming and when that didn't work … he became more and more contentious.”

In an unusual turn, Troiani and former Constand lawyer Bebe Kivitz appeared as witnesses, called by prosecutors to support their assertion that there was no nonprosecution agreement with Cosby.

Troiani and Kivitz said they had never heard of such an agreement from either Castor or Cosby's lawyers at the time, but heard it for the first time last year.

Troiani said she believed Castor refrained from pushing ahead with prosecution because of his political interests.

Cosby's attorneys challenged Troiani by saying Castor did make the agreement and did so to help Constand in the civil suit. Removing the specter of criminal prosecution, he said, would compel Cosby to testify without invoking the Fifth Amendment protection to avoid being a witness against himself.

The next step is a preliminary hearing March 8 to determine whether prosecutors have enough evidence to put him on trial.

The Associated Press contributed to this article.

szeitchik@tribpub.com