The Senate passed a sweeping criminal justice bill Tuesday that addresses concerns that the nation’s war on drugs had led to the imprisonment of too many Americans for non-violent crimes without adequately preparing them for their return to society.

Senate passage of the bill by a vote of 87-12 culminates years of negotiations and gives President Donald Trump a signature policy victory, with the outcome hailed by scores of conservative and liberal advocacy groups. The House is expected to pass the bill this week, sending it to the president’s desk for his signature.

The bill gives judges more discretion when sentencing some drug offenders and boosts prisoner rehabilitation efforts. It also reduces the life sentence for some drug offenders with three convictions, or “three strikes,” to 25 years. Another provision would allow about 2,600 federal prisoners sentenced for crack cocaine offenses before August 2010 the opportunity to petition for a reduced penalty.

Story continues below advertisement

….This will keep our communities safer, and provide hope and a second chance, to those who earn it. In addition to everything else, billions of dollars will be saved. I look forward to signing this into law! — Donald J. Trump (@realDonaldTrump) December 19, 2018

The vote also thrilled Democrats. Sen. Cory Booker, D-N.J., said the nation’s prisons are full of Americans who are struggling with mental illness and addiction, and who are overwhelmingly poor. He said the nation’s criminal justice system “feeds on certain communities and not on others,” and said the bill represents a step toward “healing” for those communities.

“Let’s make no mistake, this legislation, which is one small step, will affect thousands and thousands of lives,” Booker said.

When the bill appeared to have stalled in recent weeks, Sen. Charles Grassley, the Republican chairman of the Senate Judiciary Committee, pleaded with Senate Majority Leader Mitch McConnell to bring it up for a vote. With Trump’s urging, McConnell eventually agreed, and voted for the bill as well.

“The First Step Act takes lessons from history and from states — our laboratories of democracy — to reduce crime, save taxpayer dollars and strengthen faith and fairness in our criminal justice system,” Grassley said.

WATCH: Trump ‘thrilled’ to support criminal justice reform bill

0:44 Trump ‘thrilled’ to support criminal justice reform bill Trump ‘thrilled’ to support criminal justice reform bill

The Senate turned back three amendments Tuesday from Republican senators Tom Cotton of Arkansas and John Kennedy of Louisiana, who said the bill endangered public safety. Supporters voiced concerns that passing any of the amendments would have sunk the bill.

Story continues below advertisement

One amendment would have excluded more prisoners from participating in educational and training programs that allow them to earn credits. Those credits can then be used to gain an earlier release to a halfway house or home confinement to finish out their sentence. Another amendment would have required that victims be notified before a prisoner gets that earlier release. The third would have required the Federal Bureau of Prisons to track and report the re-arrest rate for each prisoner who gets early release.

“While the bill has marginally improved from earlier versions, I’m disappointed my amendments to exclude child molesters from early release and to protect victims’ rights were not adopted,” Cotton said. “I also remain concerned that reducing sentences for drug traffickers and violent felons is a threat to public safety.”

READ MORE: ‘Justice’ is Merriam-Webster’s word of the year

Sen. Dick Durbin, D-Ill., said the bill already carves out some 60 different crimes that make prisoners ineligible for early release to a halfway house or home confinement. He said Cotton’s amendment was too expansive and would prevent at least 30,000 prisoners from participation.

Durbin said the Federal Bureau of Prisons also gives victims the opportunity to be notified upon a change in the prisoner’s status, but it’s a choice. He said about 10 percent of victims choose not to be notified because of the trauma involved in revisiting the crime. Meanwhile, the amendment from Cotton and Kennedy would make it a requirement.

Story continues below advertisement

“Supporting the Cotton amendment is basically saying to these crime victims, ‘We’re going to force this information on you whether it’s in the best interest of your family, whether you want it or not,’” Durbin said. “That is not respectful of crime victims.”

READ MORE: Trump says he’ll review case of U.S. Army commando charged with murdering Afghan man

The bill would affect only federal prisoners, who make up less than 10 percent of the country’s prison population.

An array of liberal and conservative advocacy groups rallied in support of the bill. For example, the Koch brothers-backed group, Americans for Prosperity, applauded senators for putting “policy ahead of politics.” The American Civil Liberties Union said the bill was “by no means perfect. But we are in the midst of a mass incarceration crisis, and the time to act is now.”

Law enforcement groups were more split. It was backed by the Fraternal Order of Police and the International Association of Chiefs of Police but opposed by the National Sheriff’s Association. The union representing federal prison guards also joined in supporting the measure.