Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A mass dismissal of wrongful convictions ─ perhaps the biggest ever ─ unfolded in a Boston courthouse on Tuesday, as prosecutors in seven Massachusetts counties dropped more than 21,000 low-level drug cases tainted by the work of a rogue lab chemist.

The number of corrupted convictions was so unwieldy that the district attorneys used compact discs to deliver lists of cases they were dropping and those they believed they could successfully re-prosecute.

By day's end, just a few hundred cases involving the disgraced chemist, Annie Dookhan, remained. The exact number may not be clear until Wednesday, when the court finishes processing the lists. The American Civil Liberties Union of Massachusetts, which fought for the dismissals, did its own tally and came up with 320 cases dropped from a total 21,907.

Defense lawyers hailed the dismissals as a triumph over a system that valued convictions over due process.

"This was a mistake that comes from the war on drugs," said Carl Williams, an ACLU lawyer.

Annie Dookhan is escorted to a cruiser outside her home in Franklin, Massachusetts, in 2012. Bizuayehu Tesfaye / AP, file

Prosecutors said they decided to re-prosecute defendants with lengthy criminal histories. But they also stressed that the abandoned cases involved people with long records and those who likely committed the offenses for which they were convicted ─ often as the result of more serious crimes. Most pleaded guilty before Dookhan's misdeeds came to light in 2012, prosecutors said.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

“If there had been evidence that any of these defendants was actually innocent, we would not have hesitated to dismiss the case outright and exonerate the defendant immediately,” Daniel Conley, the district attorney in Suffolk County, which includes Boston, said in a statement.

Conley said he'd decided to pursue 117 of the 15,570 cases undermined by Dookhan's work.

Related: Stunning’ Drug Lab Scandal Could Overturn 23,000 Convictions

The dismissals capped a five-year legal fight, longer than it took to discover, prosecute and punish Dookhan, who worked at the William A. Hinton State Laboratory Institute in Boston. She admitted to tampering with evidence, forging test results and lying about it. The former lab tech served three years in prison before being released last year.

The William A. Hinton State Laboratory Institute in Boston in 2012. Steven Senne / AP, file

Why Dookhan did it remains somewhat of a mystery. Investigators and former colleagues have said the Trinidadian immigrant seemed driven by a compulsion to overachieve, even if it meant making things up or cutting corners. She became the lab's most prolific analyst, a record that impressed her supervisors but also worried her co-workers — a concern that went overlooked, investigators found.

The prosecutors fought for a way to preserve the convictions, and leave it to the defendants to challenge them. But civil rights groups and defense lawyers argued for all the cases to be dropped, saying that was the only way to ensure justice. In January, the state's high court chose its own solution, ruling that district attorneys should focus on a small subset of cases it wanted to retry, and drop the rest.

"Some are having their case dismissed because we believe that the integrity of the system of justice is more important than their conviction."

The prosecutors delivered their answers individually Tuesday at the Suffolk County Courthouse in Boston.

Bristol County District Attorney Thomas Quinn III, from south of Boston, said that he would pursue 112 of more than 1,500 cases in which drugs were analyzed by Dookhan.

In Essex County, north of the city, authorities dropped 5,160 cases and said it would re-prosecute 55, authorities said.

Cape & Islands District Attorney Michael O'Keefe said his office would keep one case and drop 1,067.

"Some are having their case dismissed because we believe that the integrity of the system of justice is more important than their conviction," O'Keefe said in a statement. "Others whose cases are of significance and can be proven independent of the actions of this chemist will not be dismissed."

But defense lawyers and civil rights advocates said the dubious convictions made it difficult for defendants to find jobs and housing or to obtain student loans. Some defendants were convicted of more serious crimes, and the drug convictions were used to stiffen their sentences, the lawyers say. In other cases, non-citizens were threatened with deportation.

Lab scandals have undermined thousands of convictions in eight states in the past decade, according to data maintained by the National Association of Criminal Defense Lawyers. The Dookhan case isn't the only one riling Massachusetts; a second scandal, at a second lab, involving a chemist who admitted to doing drugs while on the job, has threatened thousands more convictions.

The Dookhan case has also illuminated an effort to tighten up operations at America's criminal drug labs. As the criminal justice system has grown more reliant on the work of forensic laboratories, scientists have pressed for all labs to be professionally accredited, a process that would require outside reviews ─ steps that experts say could have identified Dookhan's misdeeds much earlier.

"I think the situation might have been different at an accredited lab because there would have been more eyes looking," said Jack Mario, a retired seized-drug laboratory chemist who acted as a consultant in the Dookhan investigation.