A former California Highway Patrol officer who secretly sent himself and his colleagues nude photos of arrested women from their cell phones will spend three years on probation but will be spared jail time.

Sean Harrington, 35, pleaded no contest Tuesday morning to two felony charges of unauthorized access to a computer and copying computer data for secretly sending himself the photos of DUI suspects.

His plea deal means he'll avoid jail time but will receive three years of formal felony probation and a 180-day suspended jail sentence. He must also speak at a community violence solutions class to tell everyone what he did, prosecutor Barry Grove said.

If Harrington had gone to trial, he could have faced up to three years and eight months in prison if convicted on all counts, Grove said.

"You had a person who was in a position of public trust. We as the public gave him a certain amount of power," Grove said. "He violated that public trust, he abused his power, and now no longer forevermore is allowed to be a police officer. He will be a convicted felon for the rest of his life."

Harrington had been working out a plea agreement with his high-profile defense lawyer Michael Rains for months.

Rains said Tuesday he thinks Harrington received a harsher sentence than anyone who wasn't a law enforcement officer would have, despite potentially facing prison time for the felony charges.

"I think if this would have been a case where it was not a police officer but some other citizen who didn't have a criminal record, it would have been a misdemeanor case," Rains said.

He said because of Harrington's position of authority, prosecutors insisted on felony charges.

Rains said he thinks Contra Costa County Superior Court Judge Terri Mockler recognized that Harrington had taken steps to take responsibility for his actions, including swiftly resigning once criminal charges were filed rather than forcing the CHP to take lengthy steps to terminate him.

The judge "wanted him to benefit from education that simply putting him in jail or making him wear an electronic bracelet never would have given him," Rains said. "I think the judge was thoughtful in the sentence she imposed, and I ultimately appreciate it as his lawyer."

The deal on Tuesday is a change from when Harrington pleaded not guilty in November. Since his arrest on Nov. 3, 2014, Harrington has been out on bail, and in November, Rains had told NBC Bay Area that he was working out the plea deal and that the charges didn't "warrant custodial time."

Harrington was charged with stealing nude photos from the cellphones of two arrested women, but prosecutors said he admitted during interviews to stealing photos from women's phones four to six times during the last few years and fowarding them to colleagues.

The case, first reported by the Contra Costa Times, was blown open in October 2014, after a 23-year-old San Ramon woman said half a dozen nude and semi-nude selfies had been secretly sent from her phone to an unknown number traced to Harrington.

Harrington had forwarded the messages from his phone while the woman was in county jail after a DUI arrest in San Ramon in the early hours of Aug. 29, investigators found, after they obtained search warrants for him.

Further investigation revealed that Harrington had previously stolen private photos from the phone of a 19-year-old DUI suspect arrested in Livermore on Aug. 6 while she was in the hospital and forwarded them to his own.

DUI charges against both women have been dropped.

Neither of the other two CHP officers to whom Harrington had forwarded the photos, Robert Hazelwood and Dion Simmons, face charges.

Bay City News and NBC Bay Area's Mark Matthews contributed to this report.