SAN JOSE — A San Jose police detective assigned to the sex crimes unit lost his job and will serve at least six months in jail after he pleaded guilty Thursday to swapping sexually explicit photos with a teenage girl, prosecutors said.

Tony Fregger, 34, turned himself in on July 11, a month after his computer was seized by authorities. Investigators discovered that he had a Facebook exchange with someone he knew was a minor, and solicited and received explicit photos from the girl.

According to court documents, in January 2011 she wrote, “I’m 17 and my birthdays (sic) in February,” although her true age was 16.

Fregger replied, “You’ 17!? Oh man, I thought u were like 21! Lol!”

“Certainly as a police officer in the sex crimes unit, he knew what he was doing was illegal,” said Santa Clara County prosecutor David Ezgar. “He knew that better than anyone else.”

Ezgar said the charge covers Fregger’s conduct from the moment he knew the girl was underage until her 18th birthday in 2012.

He would not comment on whether the relationship lasted past that point, or if it ever became physical in nature.

The maximum sentence for the charge of “distributing or exhibiting harmful matter to a minor” is three years in jail. As a condition of his plea, Fregger agreed to resign from the police force. He had worked as a San Jose officer since 2005.

“He has paid a severe price,” said Ezgar. “He has lost his job, his reputation and will be incarcerated like the criminals he used to investigate.”

Fregger’s defense attorney could not be reached for comment on Thursday.

He will be sentenced on Feb. 21. At that time, the judge will determine whether the crime will be reduced to a misdemeanor, which would mean Fregger would not have to register for life as a sex offender.

Ezgar said there is no indication that Fregger engaged in similar conduct with other minors.

Contact Eric Kurhi at 408-920-5852. Follow him at Twitter.com/erickurhi.