Porter's attorneys immediately said they would seek an injunction to block the ruling.
Williams said he found himself in "uncharted territory" but felt the law was "clear." He granted Porter a type of immunity that allows his charges to stand, but which precludes his testimony in the trial of Officer Caesar R. Goodson Jr. from being used against him.
Legal experts — and Williams — said the ruling was unprecedented for a criminal defendant with pending charges.
Williams also warned prosecutors that calling Porter as a witness could have serious implications for their ability to retry him. Porter's trial on manslaughter and other charges ended last month in a hung jury, and he is scheduled to be tried again in June.
"The second he testifies, that may change the game," Williams said.
After Williams issued the ruling, defense attorney Gary Proctor leapt to his feet and told Williams he intended to appeal to the Court of Special Appeals on Thursday to block prosecutors from calling Porter to testify.
Should Williams' ruling stand, Porter would not be able to invoke the Fifth Amendment and would have to testify or face the threat of contempt and jail time.
Legal experts said Porter's appeal has the potential to freeze proceedings in Goodson's trial for second-degree depraved-heart murder, which is scheduled to begin Monday with jury selection.
"It's certainly possible that the case may be stayed pending the disposition of these issues that are being raised," said appellate attorney Andrew H. Baida, who is not involved in the trials.
Prosecutors and the officers' attorneys are forbidden to discuss the case because of a gag order.
Goodson was driving the police transport van inside which prosecutors say Gray suffered a fatal neck injury in April. Goodson is the second of six officers to go to trial. All have pleaded not guilty.
Prosecutors had planned to try Porter first and then call him as a "material witness" at the next two trials. That was thrown into question when jurors deadlocked on all charges against him in December.
Prosecutors have said they intend to retry Porter in June, which raised legal questions about whether he could be compelled to testify at the other officers' trials.
Williams said it was a "simple decision in one sense" to determine that preventing Porter's testimony from being used against him would not violate his rights. Williams said it was "very clear" that compelling his testimony would not conflict with the Maryland or U.S. constitution.
Typically, the right to protect one's self against self-incrimination outweighs the state's desire to call someone as a witness against their co-defendants, attorneys and legal observers said.
Attorney Adam Ruther said that as a city prosecutor he had explored ways to call defendants, being tried separately for the same crime, to testify at each other's trials, but said there was no case law to cite as precedent.
"All I would have been left with to argue when faced with the situation the state was in was that there isn't any law that says you can't do this," Ruther said. "That's not normally a position you want to argue from. But if the evidence was important enough, that was a risk worth taking."
Defense attorney Warren Brown said it was "almost sacrilegious to make a defendant testify by giving him or her immunity, and that's why it has never occurred."
"No one wants to be in the position of being made by the government to give information that might impact negatively on themselves," said Brown, who watched in the courtroom as Williams issued his ruling but is not involved in the case. "It might open some doors here that might severely impact the right of people to get a fair trial in multi-defendant cases."
Last year, some believed prosecutors had been dealt a blow when Williams ordered separate trials for the officers, instead of in two groups as they requested. Law professor Douglas Colbert said Wednesday's ruling showed how the cases' being severed could be an advantage for the state, because Porter could not have been forced to testify against his fellow officers if they had been tried together.
"The local prosecutor is doing something most prosecutors never do," Colbert said. "They're not only bringing charges [against police officers], but they're determined to convict."
Porter's attorneys had argued that he could be subject to perjury charges or become exposed in a federal investigation if he is called to testify at Goodson's trial. They said the FBI has an open probe and has interviewed witnesses.
Porter gave a statement to police investigating Gray's death and testified in his defense at his trial.
Porter took the witness stand briefly at Wednesday's hearing and was questioned by Chief Deputy State's Attorney Michael Schatzow.
"Is it your intention, Mr. Porter, to invoke your Fifth Amendment protection to be called as a witness against Caesar Goodson?" Schatzow asked.
"Yes," Porter responded.
Proctor then asked if Porter also intended to invoke protections under Article 22 of the Maryland Constitution, which says that "no man ought to be compelled to give evidence against himself in a criminal case."
Proctor had suggested before Williams' ruling that compelling Porter to testify in the Goodson case could have broad implications in the local court system when it comes to multi-defendant criminal cases.
"The cat's going to come out of the bag," he said.
Schatzow argued that no court in the country has ever ruled that an immunity statute was unconstitutional, and that such immunity is as protective as the Fifth Amendment when it comes to a person's right not to incriminate himself.
Schatzow said the "parade of horribles" that the defense suggested would happen was not based on reality.
"Officer Porter, in the Officer Goodson case, is a witness," Schatzow told Williams in his argument. "That's the only status he has."
As to there being no precedent on the matter, Schatzow told Williams, "Somebody has to be first."
Williams retorted, "Why's it gotta be me?"
"Who would be better?" Schatzow joked.
Williams put prosecutors "on notice" that they will have "an interesting burden" to prove that they have not been tainted by Porter's testimony in Goodson's trial before they are able to try Porter again. Proctor had contended they won't be able to "un-know what they know."
Williams and the attorneys for both sides discussed the possibility of a "Kastigar hearing" — a proceeding before Porter's retrial in which the burden would be on prosecutors to prove that they had not improperly used anything from Porter's testimony in Goodson's trial in preparation for their second run at prosecuting Porter.
Williams also made reference to a "taint team," or a panel of attorneys who would be brought in to assist in assuring that prosecutors have not been tainted by hearing Porter's testimony against Goodson.
Most appeals are heard after the conclusion of trial proceedings, but under certain circumstances the appellate courts can hear motions on an emergency basis.
Richard C.B. Woods, a defense attorney not involved in the Gray case, initially said he disagreed with Williams' ruling about co-defendants being granted immunity to testify against others. But after rereading the statutes and cases cited in court, he said Williams appeared to be on solid footing.
However, Woods said the prospect of federal charges and the implications of his forced testimony would be Porter's strongest argument on the appeal.
"Immunity in Maryland is not going to do a damn bit of good for this guy in federal courts," Woods said.
Earlier in the day, Williams ruled on several other motions, including denying another request to move the case out of Baltimore. Williams said he still had "faith in the system" despite Porter's mistrial, noting a jury had been picked in two days. Jurors will again be kept anonymous but will not be sequestered.
The defense unsuccessfully tried to prevent state medical examiner Carol Allan from being called as a witness, but Williams said they could challenge her credentials at trial.