BOSTON (Reuters) - Massachusetts' top court on Monday paved the way for potentially thousands of people convicted of drugs crimes to be re-tried because their cases involved evidence from a rogue crime lab scientist.

The decision from the Supreme Judicial Court is the latest fallout from one of the country's biggest crime lab scandals, in which scientist Annie Dookhan tainted as many as 40,000 drugs cases at the now-closed Hinton State Laboratory Institute by falsifying results.

Defendants who seek new trials "cannot be charged with a more serious offense than that of which he or she initially was convicted under the terms of a plea agreement and, if convicted again, cannot be given a more severe sentence than that which originally was imposed," the court's panel of justices said.

The American Civil Liberties Union of Massachusetts, which had asked the court for measures to protect convicts seeking new trials from retribution, applauded the decision. It had argued many convicts were living with unearned criminal records because they were too afraid to have their cases reopened.

"This decision tells them that they are not going to be punished for challenging their conviction," said Matthew Segal, the legal director of ACLU Massachusetts.

Dookhan pled guilty in 2013 to tampering with evidence at the Hinton lab, where she worked from 2002-2011. She is serving a three-to-five year prison sentence.

Investigators have said her mishandling of evidence may have tainted cases involving as many as 40,000 people, shaking the foundations of the state's criminal justice system. Prosecutors estimate that about 20,000 of those cases resulted in convictions.

More than 300 people convicted of drug violations have been released from prison as a result, and many others are seeking retrials.

(Reporting by Richard Valdmanis; Editing by Grant McCool)