A man protests in front of the Baltimore City Circuit Courthouse East, after a mistrial was declared in the trial of Officer William G. Porter. (Mark Wilson/Getty Images)

A judge ruled Wednesday that Officer William G. Porter, who is awaiting retrial in the death of Freddie Gray, will have to testify against colleagues who also are charged in the case, a decision legal experts say is unprecedented in Maryland.

The ruling by Judge Barry G. Williams is a significant win for prosecutors, who have said Porter’s account is key to gaining convictions against two other officers.

But Porter’s defense attorneys indicated that they would fight the decision before the Maryland Court of Special Appeals. They argued in court that forcing their client to take the stand would injure his right to a fair trial, even though prosecutors would be barred from using his testimony against him.

“I find myself in uncharted territory,” Williams said before declaring that Porter can be compelled to testify.

The judge warned prosecutors that if Porter does take the stand against others it would be “nigh impossible” to prove his testimony would not have an impact on his retrial and said that was a burden they would face.

The booking photo provided by the Baltimore Police Department shows Officer Caesar R. Goodson Jr., who is charged in the death of Freddie Gray. (Baltimore Police Department)

The decision came in a motions hearing ahead of the trial of Officer Caesar R. Goodson Jr., 46, who has pleaded not guilty to second-degree depraved-heart murder, manslaughter and other charges in Gray’s death. Goodson’s trial is scheduled to begin Monday, but that could be delayed if Porter’s attorneys successfully win an injunction to file an appeal.

Gray, 25, suffered a severe neck injury in the back of the police van that Goodson was driving April 12, prosecutors said. Gray died a week later, igniting civil unrest and later rioting in Baltimore and fueling the national debate over police-involved deaths of young black men. In all, six officers involved in Gray’s arrest and transport have been charged in the case.

Porter’s first trial ended in December in a hung jury. He can be compelled to testify against co-defendants, legal experts said, if prosecutors grant him “use and derivative-use immunity,” which means the state cannot use anything the officer says or anything they discover from his testimony against him during his retrial. If Porter refuses to testify, he could be held in contempt of court.

Immunity is usually granted in cases­ where witnesses testify before a grand jury or are offered plea deals but is rarely applied for someone awaiting trial, said longtime Maryland defense attorney William Brennan, who is not connected with the case.

“This is not a routine procedure at all,” Brennan said. “Everyone is probably pulling out their rule books for this one.”

Prosecutors allege that Gray’s death could have been prevented had he been buckled into the back of the police wagon and received immediate medical attention.

Goodson’s attorneys are expected to argue that the officer acted reasonably based on his training and department practices and that he could not have foreseen Gray’s death.

Porter responded to the scene after Goodson called for backup to check on Gray’s condition in the back of the van. At Porter’s trial, the officer took the stand in his own defense and said Gray wasn’t showing any obvious signs of distress when he requested a medic. Porter also testified that it was the responsibility of the van driver — Goodson — to ensure the safety of those in custody.

Chief Deputy State’s Attorney Michael Schatzow said that prosecutors intend to compel Porter’s testimony in the cases against Goodson and Sgt. Alicia White, who faces manslaughter and other charges; and that the immunity provided will preserve Porter’s right to a fair trial. Schatzow said the arrangement is “necessary to the public’s interest.”

But Porter’s attorneys said that, because of his Fifth Amendment right against self-incrimination, he should not have to testify. They also argued that in Porter’s second trial, it would be difficult for prosecutors to avoid using anything he said as a witness, saying it would be impossible to remove from their minds any new information they heard while he testified.

“You can’t unring that bell,” Porter’s attorney Gary Proctor said.

Federal officials also are reviewing the Gray case, and Porter’s attorneys worried that the officer’s testimony as a witness in Baltimore City Circuit Court could be used against him if he is charged in U.S. District Court. But Schatzow dismissed such concerns, saying laws were in place to prevent that from happening.

Longtime Baltimore defense lawyer Warren A. Brown said he was surprised by the judge’s “extraordinary” decision, which is “venturing down a path the courts have never ventured down before in Maryland.” Prosecutors would have a very heavy burden of proving that Porter’s retrial won’t be tainted by his witness testimony, Brown said. The state may need to consider having a new set of prosecutors in Porter’s retrial, he said, to avoid any appearance of impropriety.

“It opens some doors here that might severely impact the right of people to get a fair trial in multi-defendant cases,” Brown said.

Doug Colbert, a University of Maryland law professor who has been watching the proceedings, said the judge’s decision was a huge victory for prosecutors and for those who want to learn what exactly happened to Gray.

“It protects the witness against self-incrimination because they can’t use the witness’s testimony against him, but it also allows the government to prosecute,” Colbert said. “Otherwise, every time you had co-defendants, they’d all gang up together and say: ‘Everybody keep quiet. Let’s have a code of silence.’ ”