A western Illinois sheriff accused of cyberstalking and threatening a woman he met at a gym pleaded guilty to attempted misconduct and resigned from office on Thursday, Attorney General Lisa Madigan said.

Rock Island County Sheriff Jeffrey Boyd, 48, also withdrew from the November ballot and will forfeit the pension he earned during his nearly four years as sheriff, Madigan's office said.

Boyd was accused of using his position as sheriff to intimidate and threaten a woman he met at a Rock Island gym. He also allegedly pursued the woman, who entered the country illegally from Mexico, via repeated text messages.

Prosecutors said the woman asked Boyd to leave her alone, but he used his law enforcement position to continue to intimidate and harass her. Then in June, authorities said, Boyd sent the woman an anonymous, threatening text message.

"Mr. Boyd was elected by the people of Rock Island County to serve as its top law enforcement officer, but unfortunately he attempted to use his position to intimidate and stalk his victim," Madigan said.

Boyd is forbidden to contact the woman as part of the plea agreement.