SACRAMENTO — California on Tuesday agreed to end its unlimited isolation of imprisoned gang leaders, restricting a practice that once kept hundreds of inmates in notorious segregation units for a decade or longer.

No other state keeps so many inmates segregated for so long, according to the Center for Constitutional Rights. The New York City-based nonprofit center represents inmates in a class-action federal lawsuit settled Tuesday on behalf of nearly 3,000 inmates held in segregation statewide.

The state is agreeing to segregate only inmates who commit new crimes behind bars and will no longer lock gang members in soundproofed, windowless cells solely to keep them from directing illegal activities by gang members.

“It will move California more into the mainstream of what other states are doing while still allowing us the ability to deal with people who are presenting problems within our system, but do so in a way where we rely less on the use of segregation,” Corrections and Rehabilitation Secretary Jeffrey Beard said in an exclusive interview with The Associated Press.

The conditions triggered intermittent hunger strikes by tens of thousands of inmates throughout the prison system in recent years. Yearslong segregation also drew criticism this summer from President Barack Obama and U.S. Supreme Court Justice Anthony Kennedy.

The lawsuit was initially filed in 2009 by two killers serving time in the security housing unit at Pelican Bay on California’s North Coast. By 2012, Todd Ashker and Danny Troxell were among 78 prisoners confined in Pelican Bay’s isolation unit for more than 20 years, though Troxell has since been moved to another prison. More than 500 had been in the unit for more than 10 years, though recent policy changes reduced that to 62 inmates isolated for a decade or longer as of late July.

The suit contended that isolating inmates in 80-square-foot cells for all but about 90 minutes each day amounts to cruel and unusual punishment.

About half the nearly 3,000 inmates held in such units statewide are in solitary confinement. Inmates have no physical contact with visitors and are allowed only limited reading materials and communications with the outside world.

The settlement will limit how long inmates can spend in isolation, while creating “restricted custody” units for inmates who refuse to participate in rehabilitation programs or keep breaking prison rules.

They will also house those who might be in danger if they live with other inmates. For instance, 71-year-old Hugo Pinell was killed by fellow inmates in August just days after he was released from isolation, decades after he became infamous for his role in a failed 1971 San Quentin State Prison escape attempt that killed six.

Beard said the settlement expands on recent changes.

Officials have reduced the number of segregated inmates statewide from 4,153 in January 2012 to 2,858 currently. They are reviewing each inmate’s case to see if they can be transferred out of the segregation units or if they qualify for a program that lets them gradually earn their way out by behaving and avoiding gang activity.

Until recently, gang members could serve unlimited time in isolation. Under the settlement, they and other inmates can be segregated for up to five years for crimes committed in prison, though gang members can receive another two years in segregation.

Beard said the segregation system was adopted about 35 years ago after a series of slayings of inmates and guards and wasn’t reconsidered until recently because California corrections officials were consumed with other crises, including severe crowding.

“We probably had too many people locked up too long, because over 70 percent of the people that were reviewed were actually released, and we’ve had very, very few problems with those releases,” Beard said.