(Reuters) - A former Arkansas district judge has been sentenced to five years in prison on charges that included granting leniency to defendants in his court if they gave him sexual favors in return, U.S. prosecutors said on Wednesday.

Joseph Boeckmann, 71, pleaded guilty to charges including wire fraud and witness tampering as well as corruptly using his official position as a district judge, the U.S. Department of Justice said.

Boeckmann, a judge in Wynne, Arkansas, resigned in 2016 after a state judicial review commission accused him of taking thousands of lewd photographs of young male defendants and sometimes spanking them. In return, it said, he reduced their sentences or paid their fines from his personal funds.

In a 21-count federal indictment unsealed a few months after he stepped down, U.S. prosecutors said Boeckmann offered to dismiss the case of two young men in exchange for the defendants being photographed naked or being paddled on their bare buttocks, the indictment said.

Boeckmann was also accused him of giving sentences of “community service,” where defendants would do work around his home. He was also accused of filing false paperwork to cover up what he did, the indictment said.

The most serious of the charges could have brought up to 20 years in prison, U.S. prosecutors have said.