NORRISTOWN, Pa. — A prosecutor who decided more than a decade ago not to bring sexual assault charges against Bill Cosby shut down the investigation while police were still working the case, a detective testified Thursday at the comedian’s trial.

District Attorney Bruce Castor abruptly closed the probe in 2005 hours after police met to review their next steps, Cheltenham police Sgt. Richard Schaffer told jurors in testimony that could blunt efforts by Cosby’s lawyers to argue that Castor, long out of office, saw no case.

“We had been discussing investigative leads and where they were going,” Schaffer, a witness for the prosecution, said on Day 4 of Cosby’s trial.

Cosby, 79, could spend the rest of his life in prison if convicted of drugging and molesting Andrea Constand, a former employee of Temple University’s women’s basketball program, at his suburban Philadelphia home. He has said the 2004 sexual encounter was consensual.

Cosby acknowledged in a 2005 police interview that he fondled Constand after giving her what he said were cold-and-allergy pills to help her relax, according to a statement introduced in court Thursday. But he said that they had a romantic relationship and that she did not object to his advances.

Castor ended the investigation after four weeks, announcing that Cosby would not be charged because the evidence had shown both parties “could be held in less than a flattering light.” He said he was concerned that Constand had stayed in touch with Cosby and waited a year to call police.

A new set of prosecutors brought charges against Cosby in 2015, after a judge unsealed the comic’s testimony from a lawsuit brought against him by Constand. In his deposition, he talked about giving quaaludes and alcohol to women he wanted to have sex with.