SALEM — A Newton man whose case exposed a potential gap in the state’s bail law pleaded guilty Monday to charges of child rape and child enticement. 

David Barnes, 45, of Waban, a former senior chemist at pharmaceutical maker Novartis, was sentenced to five years in state prison, to be followed by five years of probation, during a hearing in Salem Superior Court. 

The sentence imposed by Judge Thomas Drechsler was the result of a plea agreement in which prosecutor Karen Hopwood agreed to reduce the lead charge from aggravated child rape, which carries a 10-year mandatory minimum, to child rape, re-indict Barnes under a different section of the child enticement law and drop charges of sexual conduct for a fee and electronic enticement of a child. 

Hopwood told the judge that the plea agreement spares the victim, now 16, from having to re-live the experience by testifying at trial. 

Drechsler said he would accept the agreement “as a recognition of the defendant’s prompt acceptance of responsibility.” 

“The commonwealth has given him some credit, some consideration for that,” said the judge. 

The girl, who was a 15-year-old freshman in high school, told investigators she had encountered Barnes on Snapchat, and that the two had been communicating with each other for a couple of months before agreeing to meet near her school so he could take her to the Fairfield Inn in Amesbury on April 25 last year, Hopwood said. 

The girl did not realize how old Barnes was at the time, she said. 

She told police that Barnes picked her up in a blue Tesla and drove her to the Fairfield Inn, where they went in through a side door. In the room, Barnes told her to shower, then engaged in unprotected intercourse, told her to shower again, and drove her to a street near her home. 

As she got out of the Tesla, she told police, Barnes gave her $300. 

The girl told a friend, who told an adult, which is how it came to the attention of Amesbury police the following day. 

Hopwood said investigators learned that Barnes, before picking the girl up near her school, had stopped at the hotel first to pay for a room. Police used the girl’s description and other information to identify Barnes. 

Asked by Drechsler if that was what happened, Barnes briefly questioned the account. “It’s substantially true,” Barnes, who holds a doctorate in chemistry, told the judge. “I do not recall her telling me she was a freshman, but substantially, big picture, yes.” 

Under the law, prosecutors are not required to prove that Barnes knew the girl was below the age of consent, which is 16. 

During the hearing there were other legal questions that emerged. 

Barnes’ case led to a ruling by the Supreme Judicial Court in January that aggravated child rape, where the aggravating factor is an age difference of 10 years or more, does not trigger a provision in the bail law that allows judges to consider pre-trial detention as a danger to the public because “force” is not an element of that charge — a gap that has led Gov. Charlie Baker to twice file legislation seeking to expand the list of crimes triggering detention. 

But that finding was also cited Monday in a decision by Drechsler that because no “force” was involved, the conviction does not trigger any potential future charge of Barnes as a career criminal.

Barnes, who had been out on bail since last year, had surrendered himself to custody last week in anticipation of Monday’s plea. 

Barnes, who has been ordered to have no contact with the victim, will be monitored by a GPS device after his release, with a so-called “exclusion zone” of Amesbury, meaning that he cannot enter that municipality while on probation. That area could also be expanded to include any locations where the girl attends college or gets a job, the judge ordered. 

Barnes will have to register as a sex offender and was ordered to have no contact with anyone under 18 except for his own teenage children, undergo a sex offender evaluation and treatment, and not use a computer with the exception of work-related activities. 

That prompted some discussion, because the restriction imposes a ban on social media sites. Barnes’ attorney, Christopher Coughlin, said his client may want to use LinkedIn, which could be viewed by some as a social media site. Drechsler said he would allow Barnes to make his case for being allowed to use that site after his release from prison. 

 Courts reporter Julie Manganis can be reached at 978-338-2521, by email at jmanganis@salemnews.com or on Twitter at @SNJulieManganis.