BOSTON — Thousands more drug convictions tied to testing done by criminal chemist Sonja Farak and the former state drug lab in Amherst will be dismissed after the state's highest court on Thursday ruled the "no other remedy would suffice."

The decision clears all remaining cases for so-called "Farak defendants," and directs Attorney General Maura Healey's office to pay to notify all affected individuals. The American Civil Liberties Union and the Committee for Public Counsel Services, who brought the case, said it will now begin to try to identify the individuals linked to more than 13,000 drugs samples processed during the time in question at the lab, some of whom may still be in jail.

"For years, civil rights lawyers and our clients have been saying that there was substantial wrongdoing in the Amherst lab scandal, not just by Sonja Farak but by prosecutors. Today's decision confirms that we and our clients were right," said Matt Segal, legal director of the ACLU of Masschusetts.

Supreme Judicial Court Justice Frank Gaziano, who wrote the unanimous opinion, faulted both Farak and two assistant attorneys general for failing to disclose pertinent information about Farak's mental health and substance abuse history to defense attorneys seeking to have client convictions overturned.

"We conclude that Farak's widespread evidence tampering has compromised the integrity of thousands of drug convictions apart from those that the Commonwealth has agreed should be vacated and dismissed. Her misconduct, compounded by prosecutorial misconduct, requires that this court exercise its superintendence authority and vacate and dismiss all criminal convictions tainted by governmental wrongdoing," Gaziano wrote in the 61-page decision.

Farak in 2014 pleaded guilty to tampering with drug evidence to feed her addiction, replacing some of the drugs she stole with other substances and manipulating computer systems to cover up for her actions.

Thousands of cases handled by Farak had already been dropped by district prosecutors, but the Committee for Public Counsel Services, the ACLU and others filed an additional lawsuit seeking the dismissal of all convictions for "Farak defendants."

The SJC ordered that drug convictions be dismissed in all cases where Farak signed the certificate of analysis, the conviction was based on methamphetamines and the drugs were tested during the time Farak worked in the Amherst lab, or if the drugs were tested by anyone from Jan. 1, 2009 through Jan. 18, 2013.

District attorneys had argued that Farak's misconduct did not necessarily warrant the dismissal of all cases handled by other chemists in the Amherst lab, and should be limited to convictions based on samples tested by Farak.

And although Farak admitted to tampering with a small number of drug samples tested by other chemists in 2012, the court also rejected the Attorney General's office's argument that only convictions based on lab results from June 2012 through January 2013 should be summarily dismissed.

Gaziano called the blanket dismissal of all drug convictions a "remedy of last resort."

Northwestern District Attorney David Sullivan said he hoped the SJC decision would be "the final chapter in a sad tale of a rogue chemist, a substandard Department of Public Health drug lab, and prosecutorial misconduct by two former Assistant Attorneys General."

"It reflects a decades-long attitude that drug testing for criminal cases could be done on the cheap," Sullivan said.

The two prosecutors who were assigned to Farak's case during former Attorney General Martha Coakley's tenure in the office still work for the state. Anne Kaczmarek makes $119,000 a year as an assistant clerk magistrate in Suffolk County, while Kris Foster earns $95,000 as a lawyer for the Alcoholic Beverages Control Commission.

"The government misconduct at issue also involved the deceptive withholding of exculpatory evidence by members of the Attorney General's office, who were duty-bound to investigate and disclose Farak's wrongdoing," Gaziano wrote.

Rebecca Jacobstein, staff attorney for CPCS, said defense attorneys must now begin the process of identifying defendants who may still be in jail or prison to get them released, as well as help those already out get licenses if they have been unable to do so and have their criminal records updated.

"There's a lot of work to be done, but we are incredibly pleased to have all this work to do to get these people the justice they deserve," Jacobstein said.

Neither Segal nor Jacobstein could say how many convictions would be overturned based on Thursday's SJC ruling, but Jacobstein estimated that the number of samples processed by the state drug lab in Amherst at the time in question was around 13,000.

Previously, prosecutors dropped between 9,000 and 11,000 charges tied to testing done by Farak, according CPCS, and another 36,000 charges spanning 21,000 cases tied to another disgraced former chemist Annie Dookhan were also dismissed.

"The reason why we cannot give you a clear and exact and immediate answer to how many cases there are is because the commonwealth of Massachusetts wrongfully convicted thousands of people and really didn't keep track of them," Segal said.

"The war on drugs was done on the cheap and done by cutting corners," he added.

While the ACLU and CPCS hope they won't have to go back to court on behalf of Farak defendants again, Segal said there was some concern in federal court that defendants convicted on federal charges many be serving longer prison sentences due to prior drug convictions in state court that are now being dismissed.

Distict Attorney Sullivan said he wished chemists like Farak had been drug tested themselves before they were allowed handle evidence.

"In many ways, what is predictable is preventable," Sullivan said. "Regular drug testing of Sonja Farak would have detected her addiction and prevented the wholesale dismissal of thousands of drug cases. The fact that no drug lab employee had pre-employment or post-employment drug testing was inexcusable."