WASHINGTON — It seems like an unbelievable story.

For years, a bipartisan coalition of religious leaders, scholars and activists have argued the criminal justice system puts far too many behind bars and unfairly targets black men. The coalition urged the Obama administration to adopt their recommendations for reform.

Yet Obama left office without passing legislation on criminal justice reform. Instead, President Donald Trump — known for his harsh and often racially tinged tough-on-crime rhetoric — is poised to make criminal justice reform a reality.

After being passed in the Senate on Tuesday night, a broad criminal justice reform package is expected to pass the House on Thursday before it heads to the president’s desk to be signed into law.

And the rare bipartisan consensus came directly as a result of White House involvement.

This account of how criminal justice reform came to pass is based on interviews with activists, White House and congressional aides, some of whom requested anonymity to speak more freely.

Illinois Democratic Sen. Dick Durbin, a longtime criminal justice reform advocate, put it this way: “A breakthrough I’d never expect — the election of Donald Trump as president. What does that have to do with this? He brought his son-in-law to town.”

Trump's son-in-law, Jared Kushner, made criminal justice reform a priority, having seen the federal prison system firsthand after his father, real estate developer Charles Kushner, spent 14 months behind bars for tax evasion and illegal campaign contributions. But the president's adviser wasn’t ready to agree to what longtime advocates were proposing.

The coalition had long pushed for reforms that would include: changes to mandatory minimum sentences, releasing people who served disproportionately harsh sentences for non-violent drug offenses, efforts to reduce recidivism and further reduce the sentencing disparity between crack and powder cocaine.

Kushner argued strongly that such a comprehensive approach was likely not on the table. Trump wasn’t firmly rooted in the issue and his first attorney general, Jeff Sessions, had a long history of opposing such efforts.

Instead, Kushner pressed for a narrower bill that would prioritize prison reform, specifically making education and mental health support more available to inmates to help prepare them for their release. Sentencing reforms, particularly flexibility for non-violent drug offenders, were likely too controversial and a bridge too far, Kushner said, according to sources.

Even with slimmed down goals, the president was still an obstacle.

Last January, Trump held a meeting on prison reform in the Roosevelt Room with advocates, who saw it as their last chance to get the president on board.

As they presented their statistics, facts and arguments in favor of making changes to the system, the president seemed to lose interest.

So Reed Cordish, then an aide to Kushner, interrupted the conversation.

"Mr. President, one of the most powerful things about your campaign and your message as president is you fight for the forgotten men and women, and there’s no one more forgotten than these people,” Cordish said, referring prison inmates.

Trump briefly stared at Cordish. "You're right," he said, according to two people in the room.

A few days later, at a congressional Republican retreat, Trump told lawmakers he believed prison reform was a critical issue that they needed to pass. It was then, advocates said, that they knew the legislation had a chance.

Four months later in April, the House brought up a narrow prison reform bill that Trump had indicated he’d support but did not include sentencing reform. Republicans worried sentencing reform would scare off too many GOP colleagues, while a senior White House aide said it had purposely been made more narrow to keep Sessions from killing it. Session left the administration last month.

The bill got an important lift when New York Democratic Rep. Hakeem Jeffries signed on as a co-sponsor, despite opposition from most Democrats wary of giving Trump a victory and who thought the legislation didn't go far enough.

Jeffries, a member of the Congressional Black Caucus long considered a rising star in the Democratic party, believed that a small advancement would be better than no advancement. He called the bill the First Step Act for that reason.

"We don’t care who the president is or who gets the credit. This was the right thing to do.”

Facing pushback from liberals who argued the bill was too narrow, Jeffries released a seven-page memo countering their arguments, according to a person familiar with the situation. That memo was instrumental in keeping fellow Democrats and liberal groups from sabotaging the effort. Then Jeffries and Van Jones, of the advocacy group #Cut50, worked furiously to convince Democrats to support the measure.

“Elitists will say we should have held out for a perfect bill. While sitting in their ivory table with their degrees, they will judge when these people who have paid their dues should be able to go home to their families?” a Democratic aide said. “We did the right thing. We don’t care who the president is or who gets the credit. This was the right thing to do.”

Meanwhile, Georgia Rep. Doug Collins, Jeffries’ GOP cosponsor, was able win the support of nearly every Republican in the House specifically by keeping out sentencing reform.

"It was a matter of saying, ‘Here's the issues we’re not going to be dealing with, which is some of the more controversial and expansive sentencing reforms," Collins told NBC News.

The bill ended up passing the House 360-59 in May. The overwhelming vote was noteworthy, convincing advocates the legislation might have a chance of becoming law after all.

"That’s a vote number can’t be ignored. I then thought it had a chance in the Senate,” said Mark Holden, vice president of Koch Industries and board member of the Koch-backed Americans for Prosperity. The group has been part of the bipartisan reform coalition since discussions began in the Obama administration.

But the House bill still faced uncertainty in the Senate. Reform advocates of both parties who had been working on the issue for years wanted to add back the sentencing reforms that had scared off lawmakers in the House — including easing mandatory minimum sentencing rules that forced judges to give low-level drug offenders decades in prison. They also wanted to reduce and make retroactive sentences for crack-cocaine possession, as many inmates serve sentences 100 times longer than those convicted of powder cocaine offenses.

At this point, Trump still wasn’t on board with sentencing reforms.

Enter Kim Kardashian West, who may have single-handedly changed the president’s mind.

West met with Trump at the White House in September to urge him to pardon Alice Marie Johnson, a grandmother who had received a life sentence in 1996 for a non-violent, first time drug offense. A week later, Trump commuted Johnson’s sentence, and she walked out of prison after 21 years.

Still, the First Step Act languished in the Senate. Lawmakers including Republican Iowa Sen. Chuck Grassley, the chair of the Judiciary Committee, and Illinois Democratic Sen. Dick Durbin, argued the House version was too weak. They wanted sentencing reform, too.

Shortly after the midterms, Grassley and Durbin announced a deal with the White House to attach sentencing reform to the House bill, a more comprehensive effort than anyone thought could get through Congress or win the support of the president.

Then Trump held an event in November publicly supporting the newly crafted legislation. The Fraternal Order of Police also came out in support, giving the measure major momentum.

On the other side of the issue sat Arkansas Republican Sen. Tom Cotton, a longtime opponent of almost any criminal justice legislation.

Senate Majority Leader Mitch McConnell had refused to bring any criminal justice reform bill for a vote before the midterms, believing it would be too difficult a campaign issue for his members.

Kushner had pressed McConnell to "jam this in" before the midterms, a White House official said, but McConnell asked Kushner to let it go until after the election. In return, the aide said, McConnell promised to whip the vote.

McConnell told Kushner to “finalize your language, shore up support,” the official added. The Senate majority leader told Republican supporters in the Senate that he would only bring the bill to the floor if they could deliver at least 65 votes.

Still, McConnell refused to prioritize the legislation, pointing instead to other priorities, including judicial nominations and funding the government.

Advocates insisted they had counted at least 70 votes in the Senate, but McConnell still refused to budge. Meanwhile, a leading law enforcement group, the National Sheriff's Association, was quietly working against the measure.

So Trump began tweeting, pressuring McConnell to bring it to the floor.

Hopefully Mitch McConnell will ask for a VOTE on Criminal Justice Reform. It is extremely popular and has strong bipartisan support. It will also help a lot of people, save taxpayer dollars, and keep our communities safe. Go for it Mitch! — Donald J. Trump (@realDonaldTrump) December 7, 2018

Both sides continued to massage the bill to enhance support, which was enough to convince more Republicans to sign on, including Sens. Ted Cruz of Texas, Thom Tillis of North Carolina, Steve Daines of Montana and David Perdue of Georgia.

At the same time, negotiations to fund the government were stalled and Arizona Republican Sen. Jeff Flake put a hold on all judicial nominations until he was given a vote on a bill to protect the special counsel. That left open more time on the Senate floor, making it difficult for McConnell to continue blocking the vote.

Ultimately, it passed by a margin of 87-12 on Tuesday night.

“This might be my proudest moment in eight years in the United States Senate,” Republican Utah Sen. Mike Lee said. “This bill died a thousand deaths just in the last few months alone. So even though the ultimate vote was overwhelming and supported, there were a thousand times when we had to rescue it from the fire so that makes it super gratifying.”

Grassley summed up the process to passage by referring to his fellow senators as marshmallows.

"How do you eat 10,000 marshmallows? One at a time," he said.