NEW YORK - Thousands of mentally ill New York City residents institutionalized in dormitories called "adult homes" will be given the opportunity to move into their own apartments as a result of a legal settlement announced Tuesday.

The deal between the state, the U.S. Justice Department and several advocacy groups will end nearly a decade of litigation regarding the homes, some of which have been assailed by opponents for threadbare accommodations, restrictive living conditions and allegations that residents are sometimes given unnecessary medical treatment.

Under a consent decree, the state has agreed to offer assessments to at least 2,500 residents of 23 large adult homes in New York City that would determine whether they are capable of moving into supported housing, an arrangement in which people live largely independently in subsidized apartments, with occasional help from visiting caseworkers.

The administration of Gov. Andrew Cuomo has also agreed to create at least 2,000 new supported housing units to meet an expected increase in demand.

Cliff Zucker, the general counsel of Disability Rights New York, one of the organizations that sued the state in 2003 over conditions in the adult homes, said the shift will benefit residents who are capable of living by themselves, but were stuck for years in institutional settings because of barriers to placement elsewhere.

"People will have opportunities they never had before," Zucker said. "In an adult home, you may have more than 120 people under one roof. You have two or three people to a bedroom. You have assigned roommates. You can't cook your own food. At some places, you can't even choose a different seat for dinner. You can't have overnight guests. There is very little privacy. They have a terrible track record in terms of the quality of the accommodations."

One plaintiff in the lawsuit, Raymond O'Toole, said in a statement that the settlement would give him "freedom and the ability to grow." Another, Ilona Spiegel, said she was looking forward to working her way "back to independence."

The New York State Center for Assisted Living, a group that represents adult home operators, has defended the institutions as compassionate and necessary refuges for people who sometimes have no other option after being discharged from psychiatric hospitals.

In a statement on Tuesday, the group said adult home operators "share the view that residents should be given a choice of where to live including the choice to live in an adult home."

Some adult home operators have warned that many of their residents would have trouble living independently.

A federal judge in Brooklyn must still sign off on the consent decree before it takes effect.

A series of New York governors had resisted attempts to downsize the adult home system, but advocates for supported housing found a more sympathetic ear in Cuomo, who last winter put new policies in place restricting the ability of psychiatric hospitals to discharge patients to certain adult homes. The industry has sued over those regulations.

In a statement Tuesday, Cuomo said the settlement, "demonstrates New York's commitment to providing the best treatment possible for residents with mental illness."