AUGUSTA — Courtney Shea and his victim, Thomas Namer, had known each other for 20 years, “a relationship which was complicated and troubling,” according to Shea’s defense attorney.

Shea, 31, of Vassalboro, pleaded guilty Monday in Kennebec County Superior Court to murdering Namer, 69, and was sentenced to 32 years in prison.

The length of the sentence was recommended jointly by the state and defense attorney Brad Grant. It was imposed by Justice Michaela Murphy, who said that part of the reason she agreed with the recommendation is that the victim’s family approved of it.

Namer’s body was found Nov. 22 near Shea’s home on Riverside Drive in Vassalboro. Namer was stabbed three times through the neck and upper torso, said the prosecutor, Deputy Attorney General William Stokes.

Stokes showed Murphy photos of a large pool of blood outside an abandoned yellow and white trailer on property next to Shea’s mother’s.

He said investigators responding to Shea’s Nov. 22 report of a dead man found Namer’s body behind the trailer, his foot sticking out from under a large pile of logs, as well as indications his body had been dragged to the back of the trailer.

Police previously said Shea approached his stepfather and brother early that morning, saying he killed Namer and asking their help to bury him. They told him to call police, and went to make their own call until they saw Shea talking to 911 operators.

Shea told police he blacked out and killed Namer the previous night after Namer touched him sexually. Shea said that brought up memories of being sexually abused at age 11 by Namer.

At Monday’s hearing, Stokes rebutted that explanation about Namer making a sexual advance.

“Evidence connected with the investigation suggests that is not the case at all,” Stokes said. “The evidence shows Shea invited Namer to come out.”

A Kennebec Journal review of police and court records shows that Namer, of Waterville, had a negligible criminal record and was never charged with or convicted of sexual abuse.

Shortly after Namer was killed, friends from Waterville said they expected Shea to use a defense of sexual abuse because Namer was openly gay.

Stokes said the killing occurred between 7:15 p.m., when Shea texted Namer for a ride, and 7:45 p.m., when Shea called a friend for a ride after driving Namer’s car to a ball field in Waterville.

“To this day we don’t really know what motivated this killing,” Stokes said. “The only thing Shea has said is that he blacked out.”

Grant’s sentencing memo noted that “nearly all of the defendant’s problems involving the criminal justice system have occurred after the consumption or ingestion of alcohol and/or drug use.”

The memo also said that Shea “has been the victim of abuse from at least three individuals,” including a relative and close friends.

Grant said Shea had been drinking beer with friends and relatives Nov. 21 and at some point put a knife in his pocket.

“Courtney intended to give the knife to a relative as a Christmas gift,” Grant said. Shea then drank some whiskey and took medication just prior to texting Namer for a ride.

Grant said that when Namer arrived, he offered Shea some beer, which Shea declined.

“Shortly thereafter a confrontation occurred between the two whereby Courtney blacked out,” Grant wrote. “Courtney next remembers being outside of the automobile, with the knife in his hand. Courtney was standing over a lifeless Thomas Namer.”

The knife used in the murder was never found, Stokes said, despite extensive searches of waterways in Waterville.

“DNA testing of bloodstains on the leather jacket worn by the defendant on the night of Nov. 21, 2013, and a glove located in the trash receptacle in the defendant’s home matched the DNA of Thomas Namer,” according to Stokes’ memo.

Shea, a 6-foot-3, 260-pound man, apologized during Monday’s hearing for killing the 5-foot-4 Namer.

“I’d just like to say I’m sorry to those people who lost Tom,” he said. “I hope they can forgive me.”

Shea shrugged his shoulder and appeared to try to look around the courtroom as he spoke. He had handcuffs on his wrists that were shackled to a belt around his waist.

When he sat back down, Shea wiped his eyes with his hands.

Shea spent the hours after Namer’s killing drinking alcohol, including Twisted Tea, Natural Ice beer and vodka, and playing video games with friends in their Waterville apartment.

Stokes’ memo refers to Shea’s difficult childhood, including abuse and a diagnosis of attention deficit-hyperactivity disorder.

“The defendant was reportedly verbally, physically and sexually abused by one of (his) mother’s boyfriends. He was later physically abused by another of his mother’s boyfriends. He was diagnosed with ADHD at an early age (perhaps 5) and has had emotional and psychological issues for most of his life.”

Several of Namer’s friends and relatives attended the hearing. Stokes said Namer’s son opted not to attend, but indicated he approved of the proposed sentence.

Namer’s second cousin Timothy Attaya Jr. of Waterville wrote a victim impact statement to the judge telling her that Namer’s death has left a big hole in his life.

“We spoke every day,” Attaya said before the hearing. “Having him gone in an instant was a big shock to me.”

His letter said: “I can’t think of a day when Tom wasn’t running someone around to medical appointments, errands, etc. In the building where he lived, there were several older ladies that depended on him for rides, fetching their morning paper, cooking them meals or doing their grocery shopping.”