Many of the inmates spent months in solitary confinement or locked in cells. Others were denied release on parole, removed from programs, or held beyond their scheduled release dates after testing positive for narcotics, according to the complaint filed in Federal District Court in Brooklyn.

The plaintiffs, who include former and current inmates, claim that the manufacturer of the drug-testing equipment used in the prisons — Microgenics Corporation and its parent company, Thermo Fisher Scientific — failed to ensure that its devices produced accurate results.

State prison officials and the state inspector general are investigating the matter.

The state Department of Corrections and Community Supervision has begun reviewing tests taken this year that came back positive for the opioids Suboxone and buprenorphine, according to the lawsuit.

Thomas Mailey, a spokesman for the department, said the prisons had stopped using the Microgenics equipment after learning that results were inaccurate . They “immediately reversed any actions taken as a result of these tests, and restored privileges to any potentially affected inmates, ” he said, adding that prison officials were preparing a lawsuit against the manufacturer.

Prisoner advocates said the prison system had reversed some guilty findings , reinstated educational and recreational programming for inmates who had been removed from it, and released some people who were being held longer because of faulty tests. Mr. Mailey declined to say how many findings were reversed, when the state stopped using the equipment, or how officials learned the tests were faulty.