A Hanover man who attacked a woman with a sword must serve prison time, a judge ordered.

Kevin M. Keperling Jr., 34, pleaded guilty Wednesday in York County Court to a single count of aggravated assault and was sentenced to three to six years in state prison. The sentence was part of a negotiated plea agreement, according to court records.

Common Pleas Judge Craig T. Trebilcock also ordered Keperling to undergo mental-health and drug-and-alcohol evaluations, and forbade him to have contact with his victim, records state.

Penn Township Police said Keperling attacked two women with a sword in the 100 block of Stuart Avenue in the township on Jan. 4, 2012.

He was swinging the sword and threatening them, according to police.

One of the women, who at the time was 49 years old, suffered a serious hand injury when Keperling struck her with the sword, police said.