A total of 58 criminal cases on Martha’s Vineyard will be dropped as a result of the statewide drug lab scandal that unfolded four years ago involving Annie Dookhan, the former state chemist who served jail time for mishandling evidence in thousands of drug cases.

The Massachusetts Supreme Judicial Court had ordered prosecutors to submit the list of cases they would no longer prosecute due to the tainted evidence by early this week.

The 58 Vineyard cases are among 1,067 in Barnstable, Dukes, and Nantucket counties, and among nearly 20,000 statewide where district attorneys have decided not to prosecute. Cape and Islands district attorney Michael O’Keefe said this week that he will move forward with a single case, in Barnstable County.

“There’s an old saying, better that 10 guilty men go free than one innocent man be convicted,” Mr. O’Keefe told the Gazette by phone this week. “That sort of underlying principal has been of guidance to prosecutors for hundreds of years. We are very concerned with the integrity of the justice system. At the same time, this kind of crisis requires that there be some balancing of the public safety. The penalty that is being paid by society for the actions of this chemist is to dismiss thousands of cases, but at the same time, those cases where evidence independent of the action of this chemist can be brought into court, and we can meet our burden of proof, then public safety requires we go forward and maintain the conviction.”

The decision means many defendants who pleaded guilty to crimes can now have those convictions overturned. In two cases on the Vineyard, defendants who were serving state prison time had their sentences vacated or reduced. Without drug evidence, prosecutors said they had little choice but to abandon the cases.

The dismissed cases involve both the district and superior courts.

Five cases in Dukes County superior court were among the tainted prosecutions. Mr. O’Keefe declined to identify the cases.

Vineyard defense attorney Rob Moriarty experienced the drug lab fiasco from both sides. He was an assistant district attorney for the Cape and Islands district attorney when Ms. Dookhan was employed at the state lab, and recalled calling her as a witness.

He said most of the cases he worked on where Ms. Dookhan was a witness or handled evidence, have been dismissed.

“They’re all gone, and they should be gone,” Mr. Moriarty said.

He also handled tainted cases in his current work as a defense attorney.

Four of those cases were granted motions for a new trial and later dismissed after the district attorney declined to prosecute.

Mr. Moriarty praised the Cape and Islands district attorney for being ahead of the curve on the fallout from the drug lab scandal.

“I agree with what Michael O’Keefe said, they’re putting the integrity of the system over the guilt of these people,” Mr. Moriarty said. “Make no mistake, most of them pleaded guilty, they acknowledged their role. They knew what they were getting into, but they pleaded guilty on shoddy evidence.”

Ms. Dookhan was convicted of obstruction of justice, tampering with evidence, and perjury. She told police that she handled 34,000 cases that may have been tainted. She was sentenced to three to five years in state prison in 2013, and was released on parole in 2016.