In what is a perceived legal blow for prosecutors, the jury was hung and the judge declared a mistrial in the trial of Baltimore police Officer William Porter in connection with Freddie Gray's death after he sustained injuries while in custody.

Maryland circuit Judge Barry G. Williams indicated that he expected prosecutors to retry Porter.

Porter was charged with manslaughter, second-degree assault, reckless endangerment and misconduct in office in the April 19 death of Gray, 25, a week after his neck was broken during a ride in the back of a police van.

Gray's death and the subsequent unrest in Baltimore brought to the fore long-simmering tensions in the city and across the nation over socioeconomic disparity and the relationship between law enforcement and the minority communities they serve.

Prosecutors considered Porter’s case key to strengthening the case against Caesar Goodson Jr., who was driving the van. It was also seen as a signal of how the trials of the five other officers could go.

The remaining trials are set for early next year. It is unclear how the mistrial will affect the prosecution's approach on the other trials, if at all.

Related: Freddie Gray Death: These Are the Charges 6 Baltimore Officers Face

Jurors began deliberating Monday afternoon.

The judge scheduled conferences Thursday to "discuss a new trial date," indicating that he expects prosecutors to try Porter again. Williams gave Porter the option to appear Thursday, but he declined.

"You've been diligent," Williams told the jury. "Thank you for your diligence."

Baltimore State's Attorney Marilyn Mosby was in court for the announcement, but she, like all parties in the case, is still under a gag order until all six officers' trials are complete.

Porter and the defense and the prosecution attorneys all looked tense when the judge spoke to them privately before making the announcement to the court. Deputy State's Attorney Janice Bledsoe could be seen shaking her head.

During arguments, prosecutors focused on what they said was Porter's failure to take care of Gray while he was in custody by not getting him medical care or buckling his seatbelt.

Related: Prosecutors: Cop 'Criminally Neglected His Duty' in Freddie Gray Case

Chief Deputy State's Attorney Michael Schatzow said Porter, 26, "criminally neglected his duty to keep Mr. Gray safe."

The prosecution painted Porter, who grew up in the same neighborhood as Gray, as an affable young man who made good on his life.

Judge Barry G. Williams declares mistrial Wednesday for Baltimore police Officer William Porter. Art Lien

Porter, who took the stand in his defense, said that Gray was "unable to give me a reason for a medical emergency" and that it was not his duty to fasten the seatbelts of people who have been arrested in the van.

Related: Officer: Freddie Gray Gave No Reason to Call Medic

Porter faces a maximum penalty of about 25 years.

Officials in Baltimore had been calling for peace as the city awaited a verdict.

"In the coming days, if some choose to demonstrate peacefully to express their opinion, that is their constitutional right," Mayor Stephanie Rawlings-Blake said. "In the case of any disturbance in the city, we are prepared to respond. We will protect our neighborhoods, our businesses and the people of our city."

At a news conference Wednesday, Rawlings-Blake said it was important for people to respect the jury's decision.

"We cannot and will not be defined by the unrest of last spring," she said.

The city's preparedness is in response to unrest that followed Gray's funeral in April. Some protesters looted and burned businesses and violently clashed with law enforcement.

National Guard troops were called to help restore order, while President Barack Obama and Attorney General Loretta Lynch waded into the broader conversation about economic disparity and racial tension.

William Porter, one of six Baltimore police officers charged in the death of Freddie Gray, walks into a courthouse during jury deliberations Wednesday. Patrick Semansky / AP

And in the meantime, Baltimore worked to rebuild and remember.

Wednesday afternoon, government officials, activists and Gray's family were all focused on moving forward.

"With the eyes of the world on Baltimore City, we must ensure that any protests that take place are peaceful, and we must ensure that the process of healing our community continues. We must continue to channel our emotions into strong, positive change, so that, as a city, we truly see our young men of color before it is too late," Rep. Elijah Cummings, D-Maryland, said in a statement. "This is the road to more equal justice in our community."

Baltimore pastor Jamal Bryant said he was "disappointed" by the mistrial.

"I think it went botched, I don’t feel as if the prosecution was at tight as it needed to be by virtue of the fact that the jury still had a whole lot of unanswered questions," he said. "To be clear that they were deadlocked on all four charges and got no clarity or consensus on any of them. So I hope that in this retrial they’ll be more clear about how it is they present the case."

Activist groups had taken out permits ahead of time for possible protests, and crowds began gathering near the courthouse and the scene of Gray's arrest.

Tessa Hill-Acton, president of the Baltimore chapter of the NAACP, also called for protests to remain peaceful.

"People want a conviction. They want someone to pay for Freddie's death," Hill-Acton told NBC station WBAL. "Show your anger, protest in the good way — but don't do anything in anger."

Bill Murphy, the Gray family's attorney, stressed that the family wasn't angry and that others should remain calm. He described the mistrial as "a bump on the road to justice."