SAN JOSE — Samuel Neipp, a former South San Jose middle-school music teacher charged with sexually grooming and abusing two of his female students, has pleaded no contest to a dozen charges and agreed to a 56-year prison sentence, according to authorities and court records.

Neipp was held up as one of the most egregious local cases of its kind in recent memory, and he is the subject of two civil lawsuits that allege school officials mishandled or downplayed his misconduct. One lawsuit wants the Santa Clara County Superior Court to mandate broad restrictions on social-media and text-messaging interaction between teachers and students.

For the first reported victim, he pleaded no contest to five counts of lewd and lascivious acts with a minor under 14 by force, violence, duress, menace or fear; and four counts covering sexual penetration, oral copulation, unlawful sexual intercourse, and sending harmful matter to a minor with intent to commit a sex crime, all with a minor under 16 by an offender over 21.

For the second victim, he pleaded no contest to two counts of lewd and lascivious acts with a minor under 14. He also pleaded no contest to a count of child-porn possession.

Neipp, who taught at Dartmouth Middle School when the crimes occurred, was initially charged with 43 counts. Deputy District Attorney Carolyn Malinsky said the plea agreement, reached last week, spares the victims from trial and still ensures Neipp is in prison “until he is a very old man.”

“No sentence can undo what he did, but this sentence protects the community and gets justice for the victims,” Malinsky said. “It holds him accountable for the horrific conduct that he did.”

Neipp, a Gilroy resident, has been jailed on $2.375 million bail since his arrest. His defense attorney declined comment on the plea.

San Jose police arrested Neipp in October 2017 after allegations that he threatened to post nude photos online of one of his victims, who later accused him of molesting her for about three years starting when she was 13 and a student at Dartmouth. A second victim came forward with similar accusations, dating back earlier, after hearing that Neipp had been arrested.

Malinsky lauded the victims, identified in court as Jane Doe 1 and Jane Doe 2, for coming forward to police, which she contends finally stopped Neipp from preying on young girls.

“They are incredibly strong, amazing women,” she said. “Jane Doe 1 came forward even though the crime was still continuing. Jane Doe 2, who had put this in her past, was willing to bring it back up to come forward and support Jane Doe 1. It’s a testament to their strength.”

Jane Doe 1 alleged that starting around 2014, Neipp “texted her that he found her attractive and that he liked her,” and spent time with her alone in his office, which eventually led to them engaging in sex acts. Even after she went to high school, Doe alleges that Neipp continued to sexually abuse her as a high school student when she visited the Dartmouth campus.

Jane Doe 2 alleged that around 2009, Neipp began sending text messages and emails to her and regularly spending time alone with her in his classroom, and arranged for her to be his classroom aide. From there, Neipp began making sexually suggestive remarks, holding her hand, and kissing and touching her while they were alone together in his classroom, her lawsuit states. She also alleges that the abuse continued after she graduated and visited the middle school.

Both lawsuits contend that district officials admonished Neipp but never formally punished him for similar texts with another student, reportedly telling him in a letter that while his behavior was “inappropriate and did not show good judgment,” the matter was going to be kept “confidential.” Other documents presented by the civil attorneys suggest that administrators discussed whether his conduct was that of “a pedophile fishing for victims,” but that he continued to receive exemplary performance reviews, and was granted tenure, before his arrest.

The Union School District did not immediately respond to a request for comment.

Check back later for updates to this story.