A serial pedophile has agreed to be castrated as part of a plea deal after he was caught trying to sexually assault a seven-year-old girl.

Thomas Allen McCartney, 37, is classified a 'Tier Three' offender and is considered one of Louisiana's worst child predators.

McCartney has agreed to be both physically and chemically castrated as part of plea deal Tuesday in order to reduce his prison sentence - although he'll still spend 40 years in prison, according to local station Fox 12.

Louisiana is the first and only state to allow surgical castration to be used as a punishment for sex crimes.

The law only came into force at the beginning of the August - and his case is likely to one of the first times it's been applied by a court.