A Lakeville middle school principal is accused of stalking the police detective who was investigating him for electronic crimes.

Prosecutors charged 49-year-old Christopher Endicott with a gross misdemeanor for stalking after he was arrested Tuesday. He was been on leave since mid-January.

Police were investigating Endicott after a woman in the Rosemount-Apple Valley-Eagan School District reported that her phone and iPad connected to a school district server had been reset to factory presets and that she did not reset them.

Police served search warrants and learned that intrusions were coming from Endicott’s Apple Valley home and from an IP address in the Lakeville Public School District where he worked.

According to the charges, Endicott stalked the woman and several others, including the detective who began the initial investigation.