A former Los Angeles police officer pleaded no contest today to a pair of sex-related charges involving a then-15-year-old girl from the department’s cadet program and was sentenced to two years in prison.

Robert Cain, 32, whose arrest roiled the department and put a black mark on the cadet program that has long been hailed for building bridges between police and the city’s youth, pleaded guilty to oral copulation of a person under 16 and unlawful sexual intercourse.

As a result of his plea, he will be required to register as a sex offender. He was also ordered to stay away from the victim for 10 years.

Cain was a 10-year LAPD veteran, but he resigned last year following his arrest — which was made personally by then-Chief Charlie Beck.

The cadet program was already being investigated by the department following the arrest of seven LAPD cadets who were allegedly involved in the theft of three police cars. The teen girl with whom Cain was involved was one of the seven cadets, although her attorney said she is not facing criminal prosecution stemming from her arrest.

The girl read a statement in court, saying in part, “Monsters do not care about anything and have no problem hurting anyone. You took so much away for me, and that’s something I will never get back. You were an officer, someone who promises to protect people like me from people like you.”

Cain could have faced up to seven years and eight months in prison if he was convicted on all the original charges filed against him.

The teen’s attorney, Luis Carrillo, said Cain threatened the girl to keep quiet about the sexual activity, which officials said occurred during a June 14, 2017, trip to Magic Mountain.

“It’s not only a crime, it’s a moral outrage for a grown man in his 30s to take advantage of a 15-year-old little girl,” he said.

The now-16-year-old victim filed a lawsuit against the city earlier this year, alleging sexual harassment, negligence, negligent infliction of emotional distress and civil rights violations. The lawsuit did not name Cain as a defendant.

The girl claims in the lawsuit that Cain’s relationship with the plaintiff began in January 2017 and ended five months later. During that time, he gave her gifts and sent her inappropriate texts messages, the suit states.

It also claims that when Cain thought the girl was pregnant, he “gave the minor plaintiff a pill to induce abortion.”

Cain pleaded no contest Jan. 19 to two weapons-related charges stemming from a search of his home in San Bernardino County. He was sentenced to two years in county jail and four years of supervised release in that case. He pleaded no contest to one felony count each of manufacturing of an assault weapon and possession of multi-burst trigger device or “bump stock.”

Eight other weapons-related charges were dismissed as a result of Cain’s San Bernardino County plea, according to his attorney, Bill Seki.