.

A Marrero man has agreed to serve a 40-year prison sentence for fatally shooting someone who he said 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; he agreed to plead to a lesser crime.

Shelby had a previous conviction in 2008 for distributing a falsely represented controlled dangerous substance, and two-time offenders can be sentenced to as much as 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, but Shelby will not receive a longer sentence.

Shelby struck his plea deal after a jury had been picked for his murder trial, which was scheduled to start Tuesday in 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. July 6, 2013. He was apprehended a couple of weeks later in Harvey.

During questioning, Shelby told a Jefferson Parish Sheriff’s Office 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 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 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 during the trial, court records show.