The US House of Representatives approved a bill reducing the disparities between mandatory crack and powder cocaine sentences, which will now be sent for President Barack Obama's signature.
During his presidential campaign, Mr Obama said that the wide gap in sentencing "cannot be justified and should be eliminated".
More than eight in 10 of those convicted for crack offences in 1987 are black, according to Senator Pat Leahy, a top supporter of the bill when it passed earlier in the Senate.
That is "wrong and unfair, and it has needlessly swelled our prisons, wasting precious federal resources," Sen Leahy said after the House had voted.
The measure alters a 1986 law enacted at a time when crack cocaine use was rampant and considered a particularly violent drug.
It decreed that possession of five grams of crack triggered a mandatory minimum five-year prison sentence. The same mandatory sentence applied to a person convicted of trafficking 500 grams of powder cocaine.
The legislation as introduced by its lead author, Democratic Senator Dick Durbin, would have that imbalance from a ratio of 100 to 1 to 1 to 1, but deal-making to ensure its passage resulted in a compromise ratio of 18 to 1.
It also eliminated the five-year mandatory minimum for first-time possession of crack, in a rare instance of Congress repealing a mandatory minimum sentence.
"For Congress to take a step toward saying 'we have made a mistake' and this sentence is too severe ... is really remarkable," said Virginia Sloan, president of the Constitution Project.
The new legislation will apply the five-year term to someone with 28 grams, or an ounce, of crack.
Julie Stewart, president of Families Against Mandatory Minimums, said 28 grams is about what the average crack dealer might carry around.
She said politicians and the US Sentencing Commission have for years acknowledged the unfairness of the system, "but no one wanted to look soft on crime". The legislative change, she said, was "much more about being smart on crime".
Almost 3,000 people a year subjected to the mandatory sentence would be affected by the change. The average sentence in these cases would be reduced from 106 months to 79 months. Some 80 per cent of those convicted of crack cocaine offences are black.