A former Chester County judge who was forced from the bench last October after he was charged with stealing thousands of dollars in campaign money to fuel his gambling habit pleaded guilty Wednesday, state Attorney General Josh Shapiro said.

Michael J. Cabry III, who had been a Magisterial District judge, used the nearly $4,000 in campaign donations for personal expenses, including to gamble at casinos in Pennsylvania, Delaware, and New Jersey, prosecutors said.

“The defendant has taken responsibility for his actions that undermined both his authority as a judge and the public’s trust,” Shapiro said in a statement. “My office is dedicated to holding public officials who break the law accountable, without fear or favor.”

Cabry, 60, was charged in October with repeatedly withdrawing funds donated to his reelection political action committee and using the money to gamble at casinos, and to pay for laundry services, groceries, and hotel stays, Shapiro said.

Cabry, who was first elected in 2000, also failed to file his campaign finance reports for the period of time during which he was making the purchases, the attorney general said.

Cabry’s jurisdiction included municipalities in the northwestern portion of Chester County, including Elverson, Honey Brook, Wallace, West Brandywine, West Caln, and West Nantmeal. As a district judge, he handled minor criminal and traffic offenses and oversaw preliminary hearings for felony cases that move on to county court.

Cabry pleaded guilty to one count of theft by unlawful taking and three violations of the state election code, all misdemeanors for which he was sentenced to 12 months of probation by Senior Chester County Judge Stephen B. Lieberman.

He had been suspended from the bench since October and resigned Tuesday, said his attorney, Dawson Muth.

Muth disputed that Cabry stole $4,000 and estimated that the actual amount was between $1,500 and $2,000. He said Cabry does not have a gambling addiction, but turned to gambling as a form of “escape” during a dark time in his life.

“During that time period, he was watching his wife of 30 years deteriorate and die before his eyes — and his house caught on fire. It was a devastating time of his life. He used a small amount of his campaign funds, perhaps as an escape,” said Muth, who added that Cabry’s wife has since died of cancer and he remains unemployed. “He is deeply regretful for what he did.”