Two court bailiffs were shot and killed by a prisoner who managed to grab a law enforcement officer’s gun inside a Michigan courthouse on Monday afternoon, and the prisoner himself was then killed, a county sheriff said.

The shooting followed a struggle as officials were trying to transfer the prisoner from a holding cell to a courtroom where he was to appear before a judge, said Paul Bailey, the Berrien County sheriff. The prisoner broke free, shot and wounded a sheriff’s deputy, then fatally shot the two bailiffs before shooting another person who was standing in a courthouse hallway, Sheriff Bailey said.

The prisoner was then shot and killed, apparently by officials who rushed to the hallway.

“It’s a sad day,” Sheriff Bailey said, noting that he had known the bailiffs for decades; they had worked in other law enforcement roles before taking the courthouse jobs.