PORTLAND, Maine (AP) — A man accused of placing a gun to the neck of a sheriff’s deputy and pulling the trigger was convicted of murder Tuesday after a trial that focused on his state of mind.

Both sides agree that defendant John Williams fired the shot that killed Cpl. Eugene Cole last year in Norridgewock. The prosecution, though, argued he knew exactly what he was doing, while the defense claimed he was sleep-deprived and strung out on cocaine and heroin.

READ MORE: What To Know Before Booking Your Summer Trip

The jury delivered the guilty verdict Tuesday afternoon.

Cole, 61, was the first law enforcement officer to be killed in the line of duty in nearly 30 years in Maine.

Deputy Attorney General Lisa Marchese told jurors Tuesday that Williams was angry and resentful over his girlfriend’s arrest days earlier and wanted to avoid going to jail himself when he shot Cole at point-blank range.

“The point is not whether this defendant was acting irrationally,” she said. “It’s whether he was acting intentionally or knowingly.”

John Williams in court on April 30, 2018. (CBS News)

The defense contends Williams’ drug use and lack of sleep left him too impaired to meet the legal standard for intentionally killing Cole. Williams shot Cole simply to escape the situation and avoid going to jail, the defense said.

The defendant was “acting on adrenaline and instinct” when he pulled out his gun, flipped off the safety and fired, said defense attorney Verne Paradie.

Williams confessed that he “eliminated” the deputy after being beaten and taunted during his arrest several days after the killing, Paradie said. He had been hiding in the woods, was emaciated and was suffering from drug withdrawal.

READ MORE: Rideshare Customers Frustrated By Driver Shortage

Marchese referenced Williams’ arrest in her closing statement, saying she wasn’t asking jurors to condone what happened.

Cpl. Eugene Cole. (Image Credit: Augusta Police)

Testimony during the trial indicated Cole intended to arrest Williams on drug charges when the two met early April 25, 2018, in Norridgewock.

Cole slipped and fell to the ground, and his gun remained holstered, before a single gunshot hit him in the neck, just below his skull, severing his spinal cord and killing him almost instantly, Marchese said.

Williams wanted to avoid jail at all costs but was unable to think things through in that instant, Paradie said.

For a murder conviction, the prosecution had to show that Williams either intended to kill the deputy or shot him knowing he’d almost certainly die.

Cole, who lived in Norridgewock, was known for treating people humanely.

Some of the 3,600 people who attended his funeral wore T-shirts quoting the Bible verse that included the phrase “blessed are the peacemakers.”

MORE NEWS: School Bus Driver Arrested In Norfolk After Students Find Loaded Gun

(© Copyright 2019 The Associated Press. All Rights Reserved. This material may not be published, broadcast, rewritten or redistributed.)