PANAMA CITY, Fla. — A confessed rapist has agreed to be castrated in a plea deal that could save him from a life prison sentence.

Bobby James Allen pleaded guilty Monday to three counts of armed sexual battery and various other charges involving attacks that happened in 1998 and 1999. Allen filed a motion requesting castration in exchange for a reduced sentence.

Circuit Judge Michael Overstreet agreed to sentence Allen to 25 years' prison on Sept. 20 if has the procedure in the next eight days. If Allen does not go through with the operation, he faces up to life in prison.

"You understand that this procedure is the removal of your testicles?" Overstreet asked Allen.

Allen said he wanted to be castrated.

"I have spoken with all the victims," prosecutor Larry Basford told Overstreet. "They agree that this sentence punishes him and would deter him and others from similar acts."

Allen would be classified as a dangerous sexual offender and must serve every day of his 25-year sentence, prosecutors said.