WOODBURY, N.J. — A New Jersey appeals court on Thursday ordered a new trial for a police officer convicted of fatally shooting his friend while they played with a gun while watching an action movie.

Former Deptford patrolman James Stuart was convicted in October 2015 of murder and aggravated manslaughter and sentenced to 30 years in prison in the January 2013 death of David Compton. Stuart is entitled to a new trial because of errors in jury instructions, the appeals court ruled.

Prosecutors say Stuart shot Compton in the face at Stuart’s home while he was off-duty while watching “Dredd” after a night of drinking with friends at a bar. Stuart testified that Compton asked to see his gun and they pretended to fire at the TV.

Stuart said that he fell asleep and Compton loaded the gun and that when he woke up he pointed the gun at the TV again.

“I started to pull back the trigger and I heard Dave start to speak,” Stuart testified. “When I turned to look at him, I guess my hand turned with me. I heard a loud boom.”

The 27-year-old was shot in the face and died days later.

Stuart said he didn’t know the gun was loaded and would never have hurt Compton. The appeals court ruled that the jury should have been instructed not to consider the murder and aggravated manslaughter together.

“The instruction here was misleading and led to an implausible result,” the appeals court wrote in its opinion. “The defendant cannot act simultaneously with distinctly different mental states.”

The court said the jury should have been instructed to choose which, if any, of the mental states was proven beyond a reasonable doubt, in a descending order of responsibility.

The Gloucester County prosecutor’s office said it is studying the decision to determine whether it should be appealed to the state Supreme Court. If not, prosecutors said they will prepare to prosecute the case again.