State correction officials will also be prohibited from imposing solitary confinement as a disciplinary measure for inmates who are pregnant, and the punishment will be limited to 30 days for those who are developmentally disabled, the court filing says.

The agreement imposes “sentencing guidelines” for all prisoners, specifying the length of punishment allowed for different infractions and, for the first time in all cases, a maximum length that such sentences may run, the civil liberties group said. No such guidelines exist, except in cases involving certain violent and drug-related offenses.

“New York State has done the right thing by committing to comprehensive reform of the way it uses extreme isolation, a harmful and inhumane practice that has for years been used as a punishment of first resort” in prisons, said Donna Lieberman, executive director of the organization.

Several states, including Colorado, Mississippi and Washington, had begun to look into how to reduce the use of solitary confinement; a Senate judiciary subcommittee is holding a hearing next week on the issue.

Taylor Pendergrass, the lead lawyer in the case for the civil liberties group, said a small number of states had also banned or limited the use of solitary confinement for inmates under 18, in adult or juvenile detention facilities.

But given New York’s size and visibility, the agreement places the state “at the vanguard” of progressive thinking about how to move away from “a very punitive system that almost every state has adopted in one form or another over the last couple of decades,” Mr. Pendergrass said.

The agreement also calls for the N.Y.C.L.U. and the state to each designate an expert to assess current disciplinary practices across the state prisons and recommend further changes.

If the reform process is successful, the lawsuit will be settled in two years, the civil rights group said.

The filing, by lawyers for the plaintiffs and the state, asks the judge, Shira A. Scheindlin of Federal District Court in Manhattan, to delay the litigation while the process takes place. Judge Scheindlin gave that approval on Wednesday.

The agreement calls for the creation of a new post of assistant commissioner and a separate research position to allow the Department of Corrections and Community Supervision to “oversee and monitor the disciplinary system” statewide, through data collection and tracking performance, with the goal of “promoting consistency and fairness” in the imposition of such discipline.

Under the agreement, 16- and 17-year-old prisoners who are subjected to even the most restrictive form of disciplinary confinement must be given at least five hours of outdoor exercise and programming outside of their cells five days a week. The state must also set aside space at designated facilities to accommodate the minors who would normally be placed in solitary confinement.

The agreement followed months of negotiations between the office of the governor, the attorney general and the Corrections Department. The plaintiffs were represented by the civil rights organization; the law firm Morrison & Foerster, which donated its services; and a prisoners’ rights expert, Alexander A. Reinert, a professor at the Benjamin N. Cardozo School of Law.

An error has occurred. Please try again later.

You are already subscribed to this email.

Anthony J. Annucci, acting commissioner of the Corrections Department, said the agreement would result in “historic and appropriate changes in the use and conditions of special housing units.”

He added that the changes would “make the disciplinary practices in New York’s prisons more humane, and ultimately, our state’s criminal justice system more fair and progressive, while maintaining safety and security.”

“Today’s disciplinary confinement policies have evolved over decades of experience, and it is simply wrong to unilaterally take the tools away from law enforcement officers who face dangerous situations on a daily basis,” a statement released by the union said. “Any policy changes must prioritize the safety and security of everyone who works or lives in these institutions.”

There are about 3,800 state prisoners currently being held in “extreme isolation” cells, known as special housing units or S.H.U.s, according to the civil liberties group. The organization’s 2012 report, “Boxed In,” found that from 2007 through 2011, corrections officials issued such sentences about 68,000 times for disciplinary reasons. The most common infraction was failure to obey an order, which resulted in 35,000 such punishments, the data showed.

The average “extreme isolation” sentence was about five months, the report said, with nearly 2,800 sentences of a year or more.

Such prisoners are held in their cells for 23 hours a day, receive their meals through a slot in the cell door and are granted one hour of outdoor recreation in a “walled-in solitary pen,” the civil liberties group says.

Roughly half of such inmates are confined alone, while the other half are held with another prisoner in a space about the size of a parking spot, the report says.

“Double-celled prisoners experience the same isolation and idleness, withdrawal and anxiety, anger and depression as do prisoners living alone in the S.H.U.,” the report said. But such inmates also must “endure the constant, unabating presence of another man in their personal physical and mental space,” it added.

While disciplinary confinement makes up the vast majority of those placed in solitary, a small percentage of prisoners are placed there for administrative reasons or for protective custody.

The lawsuit that led to the agreement had originally been filed by a prisoner, Leroy Peoples. The N.Y.C.L.U. later took on the case for Mr. Peoples, who had spent two periods in isolation, totaling more than two years, according to the suit.

Mr. Peoples had been convicted of two first-degree rapes and had been sentenced to 13 to 16 years in prison. His infractions included possessing dietary supplement pills and the filing of false liens against prosecutors in the Queens district attorney’s office.

The civil liberties group later assumed representation of two more plaintiffs, Tonja Fenton and Dewayne Richardson, who had also each sued without a lawyer, and was intending to seek class-action status on behalf of all state inmates, Mr. Pendergrass said.

A version of this article appears in print on February 20, 2014, on Page A1 of the New York edition with the headline: New York State in Deal to Limit Inmate Isolation. Order Reprints|Today's Paper|Subscribe