The boyfriend of a slain 5-year-old boy's mother was sentenced in New Hampshire on Thursday to 22 to 45 years in prison for manslaughter and other charges that he pleaded guilty to, nearly a year after the child's body was found in a Massachusetts park.

Joseph Stapf, 31, had filed an intent to plead guilty earlier this month. He also admitted to second-degree assault, falsifying physical evidence and witness tampering in connection with Elijah Lewis’ death.

The child was discovered missing and found dead last October. An autopsy showed he suffered facial and scalp injuries, acute fentanyl intoxication, malnourishment and pressure ulcers.

MOTHER'S BOYFRIEND IN ELIJAH LEWIS MURDER CASE TO ENTER MANSLAUGHTER PLEA

"I never wanted any of this to happen to Elijah," Stapf said in court as he broke into tears. "I wish I could go back and change everything."

He added, "I loved that boy. I'm so sorry for everybody who has to deal with this."

Elijah's father, who lives in Arizona, brought Elijah to live with Stapf and the child's mother, Danielle Dauphinais, in Merrimack, New Hampshire, in May 2020.

Prosecutors said Elijah was starved, neglected and physically abused. They read a series of texts between Stapf and Dauphinais that expressed hostility toward Elijah and frustration if he didn't behave according to their wishes.

Joseph Stapf

Joseph Stapf, 31, is pictured here being escorted into Hillsborough County Court, Thursday, Sept. 29, 2022, in Nashua, N.H., for a plea hearing where he was sentenced to over 20 years in prison. (AP Photo/Charles Krupa)

Some of the texts from Stapf to Dauphinais told her to give Elijah more food to "fatten him up."

When Elijah died and child welfare workers started to investigate his disappearance, the couple put his body in a container and brought him to Ames Nowell State Park in Abington, Massachusetts, where Stapf dug a hole and buried him, prosecutors said.

Prosecutors said that when Elijah was found last October, he was 36 inches tall and weighed 19 pounds, while an average 5-year-old boy would be 43 inches tall and closer to 40 pounds.

NEW HAMPSHIRE GOVERNOR PREDICTS A 'RECKONING' THIS NOVEMBER FOR THE DEMOCRATIC PARTY

Elijah's father, Timothy Lewis, who was watching the hearing online, thanked law enforcement for helping to pursue justice for his son. A number of Merrimack officers and state police were in the courtroom.

"You could have stepped up to stop this at any point, had you been man enough," Lewis said to Stapf. "You could have brought him home to us at any point. You could have rushed him to the hospital at any point. He could still be there."

When Elijah was still missing, Stapf and Dauphinais were arrested in New York on charges of witness tampering and child endangerment. Days after their arrest, Elijah’s remains were found.

Dauphinais, 36, was indicted earlier this year on one count of first-degree murder alleging that she purposely caused her son’s death, one count of second-degree murder alleging she acted recklessly in causing his death, and three counts of witness tampering. She pleaded not guilty.

NEW HAMPSHIRE TO USE $5 MILLION IN FEDERAL FUNDING TO SUPPORT HOMELESS SHELTERS DURING WINTER

Stapf could receive several years' credit if he completes a degree and another program. It's possible he could testify against Dauphinais, although that was not brought up in court Thursday.

"We look forward to confronting Mr. Stapf at the appropriate time," Dauphinais' attorney, Jaye Rancourt, said in an email.