New York State discriminated against thousands of mentally ill people in New York City by leaving them in privately run adult homes, which effectively replaced state-run psychiatric hospitals more than a generation ago but turned out to be little more than institutions themselves, a federal judge ruled on Tuesday.

The judge, Nicholas G. Garaufis of Federal District Court in Brooklyn, ruled that the state was violating the Americans With Disabilities Act by housing more than 4,300 mentally ill people in New York City in more than two dozen adult homes. He said the residents had little hope of mingling with anyone in the wider community.

The nonprofit group that sued the state had asked Judge Garaufis to tell state officials they could no longer steer mentally ill people into adult homes. He stopped short of that but directed the state to submit a “remedial plan” by mid-October.

The ruling, which applies to mentally ill people not considered dangerous to themselves or others, suggested that the state would have to begin finding individual apartments or small homes for virtually all adult-home residents who wanted one. A spokeswoman for Gov. David A. Paterson had no immediate comment about the 210-page decision. “We’re reviewing it,” said the spokeswoman, Marissa Shorenstein.