Speaker of the House Paul D. Ryan (R-Wis.) listens to President Trump during a meeting on tax policy with Republican lawmakers at the White House in November. (Jabin Botsford/The Washington Post)

President Trump has done pretty much everything he can to make 2017 hell for congressional Republicans. But two words are about to make it all worth it for them: tax reform. House Republicans just passed the GOP tax plan, and the Senate could pass it this evening.

First, a brief rundown of what Republicans have had to put up with from their president:

All that was torture for Republicans, who had to walk a razor-thin line between distancing themselves from what the president said, did or tweeted — and keeping the mercurial president on their good side. With a few high-profile exceptions, they did it.

After Trump equated white supremacists in Charlotesville with counterprotesters, House Speaker Paul D. Ryan (R-Wis.) made clear he didn't like what Trump said. But he was also clear he's not going to do much about it beyond a 500-word tsk-tsk Facebook post that didn't even mention Trump by name.

Now their payoff for dealing with Trump is within reach: At the end of a very tough year for Republicans, the president is about to sign a bill that will make this Republican-controlled Congress the one that rewrote the tax code for the modern era. It will cut taxes for people at every income level, but mainly the wealthy and corporations.

Republicans are hoping this tax bill is a salve to GOP donors and voters still stinging about Republicans' inability to repeal the Affordable Care Act — proof that if you give Republicans the keys to governing Washington, they'll make major changes to make your life better.

“This is the greatest example of a promise being made and a promise being kept,” Ryan told reporters shortly before the House was set to pass the tax bill.

In other words: After a year of legislative failures (failing to repeal Obamacare), political drama (they lost two contested governor's seats and a Senate race in Alabama, of all places) and public-opinion struggles (Gallup found in August that just 16 percent of Republicans approved of the job Congress is doing), Republicans finally have scored a victory.

And it's a big one. There are few things more in line with Republican orthodoxy than cutting people's taxes. GOP operatives who are trying to keep Republicans in control of Congress next year say a tax cut that translates to the middle class is one of the best political victories.

This tax bill isn't without its own political risk. The bill's central premise — cut taxes for the wealthy and corporations so capital flows down to the rest of America — is at odds with today's populist environment. Polls consistently show that only a third of Americans support the bill. A new CNN poll shows that two-thirds of Americans think Trump and his family will benefit from the bill, while just 21 percent think it will improve their status.

But if Republicans' trickle-down gamble is right — or if the economy keeps growing through next year's elections, despite these tax cuts at the top — then it's a major win for Republicans. And that makes putting up with Trump so, so worth it.

It's not as though all of the president's tweeting and reneging and distracting and stewing will be suddenly forgotten or forgiven because of this legislation. Behind closed doors, a number of Republican lawmakers will tell you they're just as frustrated with Trump as GOP Sens. Jeff Flake (Ariz.), John McCain (Ariz.) and Bob Corker (Tenn.). It seems to some Republicans that he's a reflexively defensive, unreliable dealmaker who couldn't care less about the nuances of policy or the health of the party.

But Republican congressional leaders also had to be realists. Congress can pass all the bills it wants, but nothing becomes law unless the president signs it. For the same reason they didn't like it when the president went after Flake just before a key tax vote, they shied away from attacking the president when he did something controversial.

Rewriting the tax code has been a goal of Ryan's for most of his entire political career.

“It's an honor to be speaker of the House this year,” Ryan said Tuesday. “The last time [tax reform] got done, the job I had I was working the quarter-pounder grill at McDonald's.”

Steve Bell, a former longtime Senate GOP budget aide now with the Bipartisan Policy Institute, described Republicans' deal with Trump this way: “Paul Ryan may have lost some battles, but he won this war.”

This war. We are almost one year down in a Trump presidency. Just three, maybe seven, more to go.