A Marrero man has agreed to serve a 40-year prison sentence for fatally shooting someone who struck him over the head with a handgun two summers ago.

Alexis Shelby, 33, pleaded guilty Tuesday to a charge of manslaughter in the death of 47-year-old Michael Gray. He had initially been charged with second-degree murder, which is punishable by mandatory life imprisonment; but the deal allowed him to plead out to a lesser crime.

Shelby nonetheless faces four decades of prison because he agreed to be sentenced as a two-time offender. He had a previous conviction of distributing a falsely-represented controlled dangerous substance on his record from 2008, and two-time offenders can be sentenced to between half and double the maximum punishment for any crime they’re guilty of.

In Louisiana, the maximum punishment a first-time offender can receive for manslaughter is 40 years.

Shelby struck his plea deal after a jury had been picked for his murder trial, which was scheduled to start Tuesday in the 24th Judicial District Court in Gretna.

According to authorities, Shelby shot and killed Gray in the 5900 block of the West Bank Expressway about 4:30 a.m. on July 6, 2013. A U.S. marshals task force apprehended Shelby a couple of weeks later in Harvey.

During questioning, Shelby told a sheriff’s detective that he and Gray had gotten into a fight at a bar a few weeks earlier. Shelby claimed Gray hit him in the head with a handgun.

Shelby then said he saw Gray at a West Bank bar and grill on the day of the shooting and decided to take his revenge. He said he waited for Gray to leave and shot him in the head as he sat in his truck.

Shelby said he tossed the gun with which he killed Gray off the Crescent City Connection and into the Mississippi River. That version of events matched surveillance video from the scene of the slaying as well as eyewitness accounts, authorities said.

Prosecutors intended to use Shelby’s statements against him once arguments and testimony started at the trial, court records show.