MADISON, Wis. — A federal judge has signed off on an agreement that would end the use of pepper spray and nearly eliminate the use of solitary confinement at Wisconsin's juvenile prisons.

U.S. District Judge James Peterson gave final approval to the deal at a settlement hearing Thursday. It would also greatly limit when handcuffs and other restraints could be used.

The Lincoln Hills and Copper Lake prisons for boys and girls are slated to close by 2021 under a restructuring of the system approved by the Legislature and Gov. Scott Walker earlier this year.

The settlement agreement ends a class action lawsuit brought by the American Civil Liberties Union of Wisconsin and the Juvenile Law Center, which represented inmates.

The agreement calls for monitoring at the prisons so ensure the deal is complied with.