BOSTON — They were called “Dookhan defendants,” and there were thousands of them.

They had been arrested or sentenced on drug charges based on evidence or testimony supplied by Annie Dookhan, an ambitious state chemist who processed drug samples confiscated from suspects at triple the speed of her colleagues. Officials say her ambition led her to perpetrate one of the most far-reaching frauds in Massachusetts’s history.

Prosecutors say Ms. Dookhan declared drug samples positive that she had not bothered to test, tampered with evidence, forged signatures and lied about her credentials to enhance her standing in court as an expert witness. In all, her actions may have tainted more than 40,000 drug samples involving thousands of defendants.

Ms. Dookhan was caught in 2011 after forging a colleague’s initials. On Friday, she pleaded guilty to 27 counts, including obstruction of justice, perjury and tampering with evidence, and was sentenced to three to five years in prison, plus two years’ probation. Her lawyer had sought one year; prosecutors had asked for five to seven years.

When she arrived in court on Friday, Ms. Dookhan, 35, first showed little emotion, staring straight ahead with her face set. But she appeared to become upset as she answered the judge’s questions with “Yes, Your Honor,” or “No, Your Honor,” her voice halting and weak. After pleading guilty, Ms. Dookhan was immediately taken into custody.