A judge on Thursday declared a mistrial in the second trial of a man accused of shooting and wounding a police officer in a Feltonville mini market in 2013, after a prosecutor showed the wrong gun to a witness during testimony.

Philadelphia Common Pleas Court Judge Charles Ehrlich said he was declaring a mistrial out of an abundance of caution so the defendant, Eric Torres, 37, can get a fair trial.

Torres, then 31, allegedly shot and wounded Officer Edward Davies, then 41, during a struggle in the Almonte Mini Market at Fourth and Annsbury Streets on Aug. 13, 2013.

Thursday’s mistrial occurred after Assistant District Attorney Ed Jaramillo was questioning another officer, Raul Ortiz, who had also been involved in the struggle when Davies was shot in the abdomen. Authorities have said that Torres used a black .45-caliber Glock 30 to shoot Davies.

But Jaramillo showed Ortiz a silver gun, which the officer identified as the gun that Torres had in the store. Shortly afterward, Jaramillo took away the silver gun and handed Ortiz a black gun from the same evidence box.

At that point, Torres’ public defenders, Jonathan Strange and Stephanie Fennell, asked to speak to the judge, and the jury was dismissed from the courtroom.

Fennell argued for a mistrial, saying that the silver gun was not to be shown as evidence. It had been found by police during a search of Torres’ home after the shooting. Police also found heroin and drug paraphernalia at the house.

With the jury gone, Jaramillo told the judge that “it was an honest mistake.”

Ehrlich agreed, saying: “There was an error made by the prosecution, an inadvertent error.” But he said the jury had seen the wrong gun and he wanted to make sure that the evidence before a new jury would be “completely clean.”

In 2015, Ehrlich had sentenced Torres to 66 to 132 years in state prison after a jury convicted him of aggravated assault, assault of a law enforcement officer, and weapons and drug offenses. But Pennsylvania Superior Court in 2017 ordered the retrial after finding that police had no probable cause to search Torres’ home after the shooting.

Davies, now 47, said afterward that he was “disappointed” by the mistrial. “I’m tired of living this nightmare every day,” he said. “I just want this behind us.”

Jury selection for a new trial — Torres’ third — is scheduled to begin Oct. 29.