BATH, Maine — A 21-year-old Brunswick man facing 75 charges including nine of unlawful sexual contact with a child under 12 pleaded guilty Monday to 27 of those counts — including the sexual assault crimes — and will serve a total of six years in custody with 24 years probation.

After being sentenced, Edward T. Bernier of Cushing Street was immediately taken into custody at the Sagadahoc County Superior Courthouse.

Bernier had been indicted on nine counts of unlawful sexual contact for incidents occurring in Sagahadoc County between August 2011 and November 2011 with a then-7-year-old boy, as well as on 66 counts of possession or dissemination of sexually explicit materials.

On Monday, he pleaded guilty to all nine counts of Class B unlawful sexual contact with a child under 12, as well as to 18 counts of possession and dissemination of sexually explicit material of a child under 12.

Story continues below advertisement.

As part of a plea agreement, the Sagahadoc County district attorney’s office dismissed the balance of the charges.

According to court documents, a family member had allegedly viewed “numerous pictures of boys partially clothed” on Bernier’s computer in Topsham, but after informing the Sagadahoc County Sheriff’s Office was told the photos as described were not illegal.

However, law enforcement officers obtained a warrant, seized the computer and discovered “images of persons who had not attained the age of 12, engaging in sexually explicit conduct.”

Assistant District Attorney Patricia Mador told Judge Andrew Horton on Monday that investigators discovered a computer with “over 2,500 images, as well as videos.”

A subsequent investigation led by Sagadahoc County Sheriff’s Deputy Dan Reed uncovered the sexual assault of the child.

Mador said that if the case had gone to trial, she would have introduced evidence including a Skype conversation in which Bernier admitted the assault.

On Monday, the victim’s mother, sobbing, told the judge of “the impact this horrible abuse has caused.”

“He violated my son on so many levels,” she said. “My son has had his innocence taken away from him. … We feel so wronged in so many ways and are extremely resentful for the damage that was done to our son. … He has meltdowns, he can’t sleep alone, he wets the bed, he is very sad, and so am I. He is now taking medication, and so am I, to help deal with the trauma.”

She asked to have Bernier tell her son, who did not attend Monday’s sentencing, “that he did nothing wrong.” Horton agreed, and added that letter as a condition of the plea.

At Mador’s recommendation, Horton sentenced Bernier to 23 years of prison with all but six suspended, and 24 years’ probation.

She said the sentence was designed “to ensure that the state has some level of control over this defendant for as long as possible.”

Once Bernier is released on probation, he will be subject to conditions including no contact with the victim or family members, no unsupervised contact with any child under 18, sex offender counseling and lifelong registration as a sex offender.

Horton said that if Bernier were found guilty by trial, “This would be viewed as a light sentence.” He accepted the plea deal in part, he said, so the child would not have to testify at a trial.

“This is a huge breach of trust, among other things,” Horton told Bernier. “You’ve done something that … really does cause lifelong harm.”