A New Hope police officer who shot a man in the stomach while he was in police custody will not face criminal charges, Bucks County District Attorney Matthew Weintraub said Friday, because the shooting was accidental.

The prosecutor said the shooting was “neither criminal nor justified, but was excused.”

The officer, who retired Wednesday and whose name was not released, shot Brian Riling, 38, during a scuffle inside a holding cell at the New Hope Police Department on March 3. As the officer struggled with Riling, he yelled “Taser!” as a warning but mistakenly drew his gun, Weintraub said.

“Given the totality of circumstances, the officer would have been justified in using his Taser to regain control of Riling inside the holding cell, as the officer had a reasonable belief the scuffle posed a danger to his fellow officer,” he said. Because the officer believed he was pointing a taser at Riling, Weintraub said, “he did not possess the criminal mental state required to be guilty of a crime under state law.”

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

Riling was in police custody after an arrest that day on intimidation charges, according to a law enforcement source. His longtime girlfriend told police Riling had sent her over 100 text messages, threatening to attack her, calling her a prostitute, and threatening to kill himself, according to the affidavit of probable cause for his arrest.

Riling wanted his girlfriend to recant her police report that Riling had used a crowbar to break into her house while she was sleeping to ask her why she wasn’t returning his text messages, court records show.

When the woman finished her shift at a nearby restaurant on March 3, Riling was waiting for her, the affidavit said. He grabbed her by her throat and spit in her face, the woman told police. Riling was later arrested not far from the woman’s home in New Hope.

Riling was charged with felony witness intimidation, retaliation against a witness or victim, stalking, and related offenses, court records show. His attorney, Richard R. Fink, did not return a request for comment Friday. Efforts to reach Riling were unsuccessful.

After being taken into custody, Riling was placed in a holding cell and asked to remove his belt, according to surveillance footage provided by the District Attorney’s Office.

As he did so, a small object fell to the floor, and Riling stepped on it to hide it from two officers standing nearby. Thinking it was drug paraphernalia, the officers tried to retrieve it, and the three men got into a struggle. “That’s not mine,” Riling yelled at one point.

During the fight, one officer pulled out a gun and yelled “Taser” before pulling the trigger, the video shows. Riling slumped to the floor and screamed in pain.

“Was that a gun?” he asked the officers. “What are you doing? Did you shoot me with a gun?”

Riling writhed on the floor, telling the officers that it “hurts everywhere,” and repeatedly asked for medical attention. Fully eight minutes went by before the officers pulled Riling from the cell.

Medics then took Riling to St. Mary Medical Center in Langhorne, where he remained in critical condition for several days, according to the District Attorney’s Office. He was later released.

In his statement, Weintraub said the officer who shot Riling knew that Riling had been harassing his former girlfriend and accused of the burglary, and “had himself heard threats of violence made by Riling during a phone call” between the two.

The district attorney noted that the officer had holstered his Taser directly in front of his gun, both on his dominant side, his right. Authorities said that was a violation of department policy, which requires officers to keep Tasers holstered on their non-dominant sides.

It was not immediately clear Friday which model of Taser New Hope police officers carry. Generally, the devices operate in similar fashion to a gun and fire electrically charged prongs when a trigger is pulled.

In making his decision to excuse the shooting, Weintraub said he took into consideration the officer’s “decades of exemplary service.” The prosecutor did not say how long the officer had served in the department, but authorities said he had “dozens of commendations and letters” during his tenure.

New Hope Police Chief Michael Cummings did not return a request for comment.