MARTINEZ — Roughly a month before he was to be tried on murder charges, a Blackhawk man tearfully apologized for beating his wife to death with a hammer and accepted a plea deal that will put him in prison well into his 80s.

John Tercheria, 71, who once played for a Minnesota Twins minor league baseball team and was named to the National Senior Softball Hall of Fame in 2007, admitted Tuesday that he killed his wife Linda Tercheria, 71. She died in the couple’s home in August 2016, after suffering more than 20 blows to the head.

After hearing from two of his wife’s close friends, John Tercheria spontaneously decided to speak in court Tuesday, saying he is sorry for all the people he’s hurt, his attorney said. He denied a reporter’s request to interview him in jail Wednesday, and is expected to be transferred to San Quentin State Prison within a week.

In exchange for guilty pleas on charges of voluntary manslaughter, elder abuse and domestic violence with great bodily injury, Tercheria — who briefly faced the prospect of a death sentence at the start of the case — will be sentenced to 17 years and four months. With good behavior, his sentence could be reduced up to 20 percent.

It was a bizarre case made more shocking when police testimony revealed that Tercheria was having an illicit relationship with a woman who told police she gave him an ultimatum days before he killed his wife: move away with her or end the relationship.

Prosecutor Chris Walpole said friends and family members of Linda Tercheria did not want the case to go to trial. He said the plea deal “(makes) it likely that the defendant would not leave prison alive due to his age.” Tercheria’s own attorney, William Gagen, called it a likely life sentence.

Gagen said the beating was “out of character” for his client, and suggested that medical issues were a proximate cause. Tercheria, he said, had been prescribed steroids at a so-called anti-aging clinic and showed early signs of dementia.

“The evidence, even in police reports, was such that for three or four years people had noticed a change in John’s behavior, some of the things he did and his language — use of profanity, let’s say,” Gagen said, later adding, “I think the DA realized if we had a trial, there was some chance a jury would be understanding of John’s mental situation.”

But Walpole wasn’t so moved.

“Although the defendant may have had medical or mental issues, almost all defendants who commit murder have some sort of mental issue,” he said. “In this case, the defendant knew exactly what he was doing.”

Gagen also denied that Tercheria was having an affair with the star prosecution witness in the case. The woman told police that Tercheria approached her several years ago at a Target, and that the two had begun a clandestine relationship that included him watching her perform sex acts on herself. She said Tercheria, who owned a construction company, had paid her $30,000 over the years, including $1,000 around the time of the killing, according to police testimony.

“I think the evidence would really reflect that she was extorting money from him … it was much more complicated than to say they were having an affair,” Gagen said.

Tercheria’s change of plea, entered the day after Christmas, brings to its end a case that shocked the gated community of Blackhawk and surrounding cities last year. Both the defendant and the victim were well-liked in the community, and many had to cope with the fact that one of their good friends was killed by a person they trusted.

Gary Tryhorn, who used to play ball with John Tercheria, said he thought the time he will have to serve “is probably fair.” He didn’t think it was first-degree murder but more a crime of passion.

He said it was a shame that Tercheria lived his whole life, made good money, and then “does something like that.”

“It’s hard to figure,” said Tryhorn, who also received a letter from Tercheria from jail three months ago.

In the short letter, which he read to this newspaper, Tercheria tells Tryhorn that he is coming out of his depression and “feeling a little bit better now.”

Jan Lee, Linda Tercheria’s best friend since third grade, read a statement to the court on Tuesday. She does not agree with the plea deal.

“I didn’t feel it was enough. I think he should stay in prison until Linda comes back, which is never going to happen,” Lee said.

Lee said the Tercherias’ adult daughter, Lisa, has had her life turned upside down since the murder of her mother on Aug. 7, 2016. She wants everyone to remember she was a wonderful mother, and will be missed more than she will ever know, Lee said.

“I can’t imagine the complete and utter terror Linda experienced in the last minutes of her life (when she was) savagely and brutally beaten to her death with a hammer,” Lee said, later adding, “I hope the defendant will never forget the terror in Linda’s eyes for as long as he lives.”