The New Hope police officer who shot a man in the stomach in a holding cell last month was an experienced law enforcement official who made a mistake in the heat of a moment, the borough’s mayor said Wednesday.

Cpl. Matthew Zimmerman was a 33-year veteran and the second-highest-ranking member of the department when he retired last week, Mayor Laurence Keller said.

“Matt represented and protected our community for a very long time,” he said. “This incident is very surprising; it’s human error. As a police officer, those circumstances can be unfortunate, and that’s what happened here.”

Zimmerman, 65, quietly left the department two days before Bucks County District Attorney Matthew Weintraub publicly announced that the officer had shot a prisoner on March 3 in the “honest but mistaken” belief that he had drawn his Taser rather than his gun.

Weintraub declined to charge Zimmerman, ruling that the shooting was “neither justified nor criminal, but was excused.” The prosecutor noted that both the gun and Taser were holstered on the officer’s dominant side, his right, which he said was a violation of department policy.

New Hope does not have a policy barring officers from bringing firearms into holding cells, as some larger departments do. The 11-member force largely responds to quality-of-life and domestic issues in the small borough.

Zimmerman had been placed on administrative leave during the district attorney’s probe. He did not respond to a request for comment.

The mayor, in an interview Wednesday, said Zimmerman had received multiple commendations during his tenure. He said Zimmerman had never been suspended or formally disciplined during the 21 years Keller has served as mayor.

He said he believed that Zimmerman, whose base salary was $96,383, was eligible to collect a pension, but said the amount had not been calculated by the state pension office as of Wednesday.

Zimmerman’s attorney, William Goldman, said Wednesday that the officer had always “comported himself professionally” and that the shooting came as Zimmerman was confronted by a “tall, strong individual who was threatening in his words and in his actions.”

Brian Riling, 38, of Pipersville, was in custody on intimidation charges when the shooting occurred. Authorities said he assaulted and stalked his ex-girlfriend, sending more than 100 text messages imploring her to recant a report to police that he had used a crowbar to force his way into her home.

While in a holding cell, police said, Riling dropped what appeared to be a plastic baggie that the officers assumed was drug paraphernalia. He stepped on the baggie in an effort to conceal it and a struggle with officers ensued.

In surveillance video released by Weintraub’s office, Zimmerman yells “Taser!” moments before firing his gun at Riling.

Warning: This video depicts a shooting in violent detail and contains profanity.

Goldman said Zimmerman was trying to prevent Riling from hurting him or another officer. “Police officers are to be recognized for their sacrifices, and he had to make a split-second decision,” Goldman said.

After the shooting, Riling was taken to a nearby hospital, where he remained for several days in critical but stable condition, investigators said. He was discharged and released on bail, and faces a preliminary hearing in the case next month, court records show.

Riling’s attorney, Richard F. Fink, declined to comment on the district attorney’s investigation. Riling did not respond to requests for comment.

Reported cases of law enforcement officers mistaking guns for Tasers are rare.

An Oklahoma sheriff’s deputy fatally shot a prisoner in 2016 in that manner, as did a Bay Area Rapid Transit police officer in California in 2009. Both officers were charged and convicted.

Locally, a similar incident took place in York County in November. An officer from the Southwestern Regional Police Department shot a man in the back of his police vehicle during an arrest. The district attorney later charged the officer, Stuart Lee Harrison, with simple assault after he admitted that he thought he had fired his Taser. Harrison’s case is scheduled for trial later this year.