Former state chemist Annie Dookhan in Suffolk Superior Court in Boston in 2013. (David L. Ryan/Boston Globe)

The first of two massive scandals involving chemists at two Massachusetts drug labs took a major turn Wednesday when the Massachusetts Supreme Judicial Court rejected the idea of dismissing all 24,000 convictions in drug cases handled by a “rogue” chemist, but strongly urged prosecutors in eight counties around Boston to drop many of the cases so that a manageable number could be retried if needed.

The court also required prosecutors to certify they still had sufficient evidence in each of the remaining cases and to send new notifications to those defendants, all within the next 120 days.

The details of the misconduct by Annie Dookhan at a Boston-area facility for testing drugs in police cases, discovered in 2012, were shocking. She admitted to “contaminating samples intentionally, including turning negative samples into positive samples on at least a few occasions,” a state investigation of her work between 2003 and 2011 found. She falsified reports that the machine used for testing was properly functioning. She admitted to grouping multiple samples together from various cases, then testing only a few but claiming she had tested them all.

“All samples in which Dookhan was the primary chemist,” the state inspector general wrote, “should be treated as suspect and be subject to careful review.” It was another setback for forensic science, already reeling from federal criticism of their long-trusted sciences like bullet identification and tread analysis and reports of sloppy work at the FBI crime lab.

Dookhan pleaded guilty to multiple counts of tampering with evidence and obstruction of justice and served three years in prison. Then another drug lab chemist in western Massachusetts, Sonja Farak, was discovered in 2013 to have been actually using the drugs sent to her lab, was also arrested and imprisoned, and the number of cases she affected hasn’t yet been determined.

But what to do with the 24,000 Dookhan cases that ended in guilty pleas or verdicts, involving 20,000 defendants? The American Civil Liberties Union and the Massachusetts criminal defense bar wanted the state supreme court to order all the cases dismissed with prejudice, particularly as the years dragged by and only about 2,000 of the Dookhan cases were revisited and resolved. The Boston-area prosecutors said the cases needed to be reviewed one by one, with defendants filing motions if they wanted their cases reopened, and in August they sent a letter to the Dookhan defendants informing them of that possibility. The defense bar said the letter was flawed, and that the public defenders didn’t have the resources to retry 24,000 cases.

The Massachusetts high court spared no rhetoric in describing the scope of Dookhan’s deeds, calling it “government misconduct that has cast a shadow over the entire criminal justice system,” “particularly insidious” and “a lapse of systemic magnitude.” But the opinion written by Chief Justice Ralph D. Gants concluded that “a dismissal with prejudice for government misconduct is very strong medicine … and we are not convinced that it is appropriate … to prescribe it now.”

Instead the court drew up a new protocol for case-by-case resolution, considering the possibility of 20,000 motions to reconsider previously closed cases. Virtually all of the defendants have already served their sentences, but Gants noted that drug convictions continue to reverberate in their lives, costing them job opportunities or housing or financial help. Repeatedly, the court stated that “the government bears the burden of taking reasonable steps to remedy” Dookhan’s misconduct.

So the court ordered the district attorneys with Dookhan cases to review all of them and determine which ones could or should not be retried, urging the prosecutors to determine “whether a conviction warrants burdening the court system” with retrial motions and retrials as well as payment to defense attorneys to reopen the cases. The prosecutors must devise a list of all cases to be dismissed, and all cases sought to be preserved, within 90 days.

Next, the prosecutors must send a court-approved letter to the defendants whose cases are not dismissed within 30 days, notifying them not only of their right to reopen the convictions but also providing a “hotline” phone number staffed by public defenders to provide guidance. In addition, the Committee for Public Counsel Services, which appoints defense lawyers to the indigent, will be allowed to insert a separate letter providing further legal advice. A form enabling indigent defendants to apply for an appointed lawyer will also be included, and all of it must be sent with a self-addressed stamped envelope — all at the government’s expense.

“We recognize that this cost could be considerable,” Gants wrote, “but that is a consequence of egregious government misconduct that affected more than 20,000 defendants.” The court earlier ruled that Dookhan’s actions automatically qualified as misconduct for purposes of the criminal cases, but the state can retest drug evidence if it still exists.

If the number of defendants who respond to the letters is overwhelming, and the CPCS cannot find enough attorneys to handle the cases, the supreme court will consider simply dismissing their cases. In September, the prosecutors sent a letter to all the defendants it could locate, including a clumsily translated version in Spanish, but the court called it “wholly inadequate,” saying it failed to inform the defendants of their right to a lawyer and was sent in an envelope that looked like junk mail. It instructed defendants to call their district attorney’s office with questions and elicited a very small response.

Although there was not a blanket dismissal of all cases, “it’s a pretty big victory from our perspective,” said Matthew Segal, the ACLU’s lead counsel on the case. “This is going to do a lot of justice.” He said the ACLU’s original lawsuit in 2014 sought quick action, because Dookhan’s conduct had been public for two years at that point, and to place the burden for a remedy on the prosecution.

“What I am concerned about is whether we are going to get a responsible reaction from the DAs,” Segal said. “… At some point, common sense should take over. I can’t imagine it’s worth spending taxpayer dollars to relitigate drug cases against people who have already served their sentences. It’s astonishing that it’s even up for debate.”

But the Boston-area prosecutors were also pleased with the ruling, because they did not want to see 24,000 convictions thrown out. Daniel F. Conley, the Suffolk County district attorney, said in a statement that the court had consistently found “that prosecutors are best situated to assess the viability of their cases. … In the weeks to come, we’ll consider the quality of the evidence, the availability of our witnesses, and the relative seriousness of each specific case.”

Jake Wark, the spokesman for Conley, said that “as a practical matter, we recognize every day the distinction between those who traffic in drugs and those who are addicted to drugs,” indicating that distribution cases would get higher priority for protecting a conviction than a possession case. Although the review of 24,000 cases by seven district attorneys offices in 90 days would seem onerous, Wark said: “Our experience over the past four years has provided us a deep and distinct body of data, which we have shared with the trial court and defense bar, that will allow us to work rapidly and efficiently. There is a great deal of work to be done but we are very well situated to perform it.”

Wark noted that many cases had witnesses, police drug buys, surveillance, confessions and other evidence that could still be used to sustain convictions. He also said labs were better at preserving drug evidence, which the supreme court said could be retested by another chemist. The lab where Dookhan worked is now closed.

One Massachusetts justice, Geraldine S. Hines, wrote a dissenting opinion saying the court should have dismissed all 24,000 cases. “Now, more than five years after Dookhan’s misconduct first came to light, the need to adopt a swift and sure remedy for the harm caused by her deceit presents itself with palpable urgency,” Hines said. “The time has come to close the book on this scandal.”

Hines said the proposed case-by-case solution of the court “is simply unworkable as a timely and effective mechanism for addressing the due process claims of the thousands of defendants now deemed to have been convicted on Dookhan’s tainted evidence.”