Thousands of prisoners serving time for crack cocaine could have their sentences trimmed by several years after the U.S. Sentencing Commission voted Thursday to retroactively apply a law easing penalties for possession of the drug.

Inmates sentenced as far back as 1991 for crack crimes will be able to apply for reduced sentences. The 6-0 vote by the panel that sets sentencing guidelines used by federal judges could affect as many as 12,040 inmates, according to the commission.

The...