A Pennsylvania officer who shot and wounded an inmate because he apparently thought he was using his Taser instead of his gun will not be criminally charged, the prosecutor said.

Bucks County District Attorney Matthew D. Weintraub said in a letter to New Hope Police Chief Michael Cummings that the March 3 shooting "was neither justified, nor criminal, but was excused," according to a statement released Friday.

Weintraub said the officer had an “honest but mistaken” belief he was deploying his Taser when he shot the man.

The officer shot Brian Riling, who had been arrested on intimidation, assault and other charges, in a holding cell in the borough of New Hope. Riling survived but spent several days in critical condition, the district attorney said.

Riling had entered the holding cell and removed his belt as instructed, and what appeared to be a bag of drugs fell to the ground, Weintraub said in the statement.

Riling stepped on the bag, there was a struggle, and the officer who shot him entered the cell to help the officer wrestling with him. The officer who shot Riling yelled, "Taser!" before firing what was a firearm, the district attorney's office said.

Video released by the DA's office shows the officer appear to shoot Riling, who shouts and falls to the floor as the two officers step back.

In the video, Riling appears to say, "Was that a gun?” and "What are doing? You shot me with a gun? What the f--- are you doing?" He also talks about his kids and says he doesn't want to die.

Weintraub said the officer who shot Riling wore his Taser on his right side, in front of his firearm, which is a violation of department policy that says officers should carry their Tasers on their non-dominant-hand side.

"This violation of policy, however, does not constitute a violation of law," he said.

The use of a gun by a police officer “must be an officer’s last resort ... and was not justified in this case,” the statement from Weintraub’s office said.

But "because the officer believed he was deploying his Taser and not wielding his service firearm, he did not possess the criminal mental state required to be guilty of a crime under state law."

An email from NBC News to the office of an attorney listed in court documents as representing Riling was not immediately returned on Saturday afternoon.

The Bucks County Courier Times newspaper quoted the attorney, Richard Fink, saying earlier this week that although Riling had been released from the hospital, he was still experiencing medical problems related to the shooting.

The officer was placed on administrative leave and retired from the police department on April 10, the district attorney's office said. The police department did not respond to a request for comment.

New Hope Borough is a community of around 2,500 in Bucks County, around 30 miles northeast of downtown Philadelphia.