In August 2013, Eric Torres intentionally drove away from a Philadelphia police officer during a traffic stop and moments later fired a gun at another Philly cop, seriously wounding him during a struggle inside a Feltonville mini market, a prosecutor told a jury Wednesday.

While lying in a fetal position, Torres shot Police Officer Edward Davies in the abdomen, Assistant District Attorney Shuaiyb Newton said in his opening statement at Torres’ retrial on aggravated-assault and weapons charges.

Public defender Jonathan Strange, however, told the panel in his opening that this was a case of “police officers going totally out of control,” from overreacting to a routine traffic stop to when they “swarmed into that store.”

“Eric Torres wasn’t trying to shoot [Davies], no one was trying to shoot him,” said Strange. “It was a tragic accident” in which the gun went off during the “violent fray” involving Torres and the officers.

Torres, 37, of Feltonville, has been in custody since his arrest, and was convicted by a jury in March 2015 of aggravated assault, assault of a law enforcement officer, and weapons offenses in the shooting of Davies two years earlier. He also was convicted of assaulting three other officers. The jury had acquitted him of attempted murder in Davies’ shooting.

At a July 2015 sentencing hearing, Philadelphia Common Pleas Court Judge Charles Ehrlich sentenced Torres to 66 to 132 years in state prison, telling him: “You’re the kind of person who is a very dangerous person to society. ... I don’t want any more people to be assaulted by you, to be shot by you, or being sold drugs by you. ... I don’t want you on the streets. You’re a ticking time bomb.”

But in December 2017, a three-judge panel of the Pennsylvania Superior Court vacated Torres’ sentence and ordered a new trial after finding that police did not have probable cause to search his home after the shooting in the Almonte Mini Market at Fourth and Annsbury Streets.

At the time of the shooting, Davies, then 41, a married father of four, was a six-year veteran of the Police Department serving in North Philly’s 25th District.

After Davies collapsed in the store, another cop took him to Temple University Hospital. “All he could think of was ‘This is it, I am going to die,’ ” Newton told jurors Wednesday at the retrial in Ehrlich’s courtroom.

Davies spent a little more than a month at the hospital, where he was in a coma for three weeks, and underwent numerous surgeries including removal of a kidney. He still has nerve damage and can’t stand for long periods, Newton said.

Davies, who has since returned to the Police Department, was at the Stout Center for Criminal Justice during the second day of jury selection Wednesday, but was not in the courtroom for the opening statements.

The events leading to the shooting began shortly before noon Aug. 13, 2013, when Torres, driving a BMW with a broken brake light, was pulled over by Police Officer William Barr on Fifth Street just north of Allegheny Avenue in North Philly.

Barr, the first witness to testify Wednesday, said that Torres, then 31, handed over his driver’s license, registration, and insurance, but seemed “nervous” and “kept looking around.” Because of Torres’ “abnormal” behavior, Barr said, he asked if there was anything in the car that he should know about, but Torres became argumentative, then sped away.

Barr initially pursued in his patrol vehicle, but stopped a few blocks north on Fifth.

Torres then crashed his BMW into a fence on Bristol Street near Rising Sun Avenue in Feltonville. He went on foot to the mini market, and when he saw officers enter he tried to run out the back, but two cops grabbed him, Newton said.

Davies and another officer then arrived, and during a struggle with Torres on the ground, Torres fired the .45-caliber Glock 30 in his waistband, hitting Davies, prosecutors argue. Torres was arrested at the market and put in a police vehicle, and the gun was confiscated.

On the same day, police obtained a search warrant for Torres’ home on the 400 block of West Raymond Street, a block from the mini market. Inside, they found bulk quantities of heroin and drug paraphernalia. The jury in 2015 also had convicted Torres of possession with intent to deliver heroin and possession of drug paraphernalia.

In light of the Superior Court’s 2017 decision, attorneys at Torres’ retrial are not permitted to present evidence of drugs found at Torres’ home.

The Superior Court panel, agreeing with Torres, found no connection between the crimes for which he had been under investigation and the proposed search of his house. Torres’ “identification was not in doubt, and police already were in possession of the firearm used in the shooting,” the panel wrote.

The trial resumes Thursday and is expected to continue into next week.