A former San Bernardino County sheriff’s deputy has been sentenced to two years in prison and will have to register for life as a sex offender after his plea agreement to charges of having sex with female inmates at the Morongo Basin Station jail, the prosecutor in the case said.

Brian Derryberry was sentenced Feb. 1, San Bernardino County Deputy District Attorney Jason Wilkinson said in a recent phone interview.

Derryberry, who was charged in July 2016, pleaded guilty in Victorville Superior Court to two of the counts, sodomy with a jail inmate and making a criminal threat. Under the plea agreement reached in December, seven other charges against Derryberry were dismissed.

Wilkinson said in addition to his prison sentence and sex-offender registration, Derryberry will have to undergo mental health screenings before he is paroled.

If the screenings agree he is likely to re-offend, the matter can be referred to prosecutors who can seek a state hospital sexually violent predator commitment court hearing, Wilkinson said.

Sexually violent predator state hospital commitments are open ended. If a person is evaluated to no longer be a threat, they can petition for release.

Derryberry, who state records show had been a licensed real estate salesperson, was fired as a deputy around the same time his arrest was announced by sheriff’s investigators. The jail, which can hold 79 inmates, is part of the sheriff’s Morongo Basin Station in Joshua Tree.