Rod J. Rosenstein, then the nominee to be Deputy Attorney General, testifies before the Senate Judiciary Committee. (Aaron Bernstein/Reuters)

With the stroke of a pen, Rod Rosenstein redeemed his reputation, preserved the justice system, pulled American politics back from the brink — and, just possibly, saved the Republican Party and President Trump from themselves.

The deputy attorney general’s memo Wednesday night announcing that he had appointed Robert Mueller as special prosecutor to investigate the Trump administration’s ties to Russia was pitch perfect in its simple justification: While he has not determined that any crime has been committed, he wrote that “based upon the unique circumstances, the public interest requires me to place this investigation under the authority of a person who exercises a degree of independence from the normal chain of command.”

This is precisely what Rosenstein needed to do for all parties, but particularly for his own honor. Rosenstein, just two weeks into the job, had trashed the reputation he had built over the years as a fair-minded and above-the-fray prosecutor by allowing Trump to use him as cover for Trump’s own decision to sack FBI Director James Comey. Many who admired Rosenstein were stunned that he would let himself be used this way; I argued last week that “if he cares at all about rehabilitating the reputation he built, Rosenstein has one option: He can appoint a serious, independent and above-reproach special counsel — the sort of person Rosenstein was seen as, until this week — to continue the Russia probe.” In tapping Mueller — a solid figure who served ably as FBI director under two presidents — that’s what Rosenstein did.

Rosenstein also restores some confidence in a justice system that has been much abused by Trump’s assaults on “so-called” judges. That system was gravely wounded by Comey’s firing, ordered by Trump and overseen by Attorney General Jeff Sessions, who was supposed to have recused himself from the Russia probe but decided it was just fine to recommend the firing of the man overseeing that investigation and choose his replacement.

(Peter Stevenson,Jason Aldag,Whitney Leaming/The Washington Post)

The deputy attorney general’s decision also reduces partisan pressures that were very clearly harming the national interest. Republicans had gone into a crouch to protect against any suggestion that Trump and his advisers colluded with the Russians. Democrats were often leaping to conclude that there was high-level collusion. And nearly everybody had lost track of the most important issue: Russia, arguably our leading global adversary, had successfully meddled in a U.S. presidential election — undermining confidence in our system of government — and was ready to do it again.

In this sense, Rosenstein also did a favor for congressional Republicans. A minority of GOP lawmakers had begun to see the urgency of putting country before party. House Government Oversight Committee Chairman Jason Chaffetz (R-Utah), who is retiring, had directed the FBI to turn over documents. Sen. Lindsey Graham (R-S.C.) and others have called for Comey to testify. Sen. John McCain (R-Ariz.) invoked Watergate, Rep. Adam Kinzinger (R-Ill.) and several others joined calls for an independent commission or special prosecutor, and Rep. Justin Amash (R-Mich.) said impeachment could be in order.

Congressional Republican leaders knew something was amiss with Trump and Russia. The Washington Post’s Adam Entous reported Wednesday that House Majority Leader Kevin McCarthy last year was recorded saying that he thought Trump was paid by Russian President Vladimir Putin. But, shamefully, GOP leaders had been in denial. Senate Majority Leader Mitch McConnell was steadfast against an independent prosecutor or commission, and House Speaker Paul Ryan continued to tether himself and his party to Trump.

At a news conference Wednesday morning, Ryan, reading from a typewritten statement, gave what amounted to a generous Trump defense. Ryan alleged that “there are some people out there who want to harm the president,” and said of Comey: “If this happened as he allegedly describes, why didn’t he take action at the time?” Ryan dismissed “speculation and innuendo,” saying “there’s clearly a lot of politics being played.” He cited the acting FBI director as saying “no one has tried to impede” the FBI probe. “There is plenty of oversight that is being done,” Ryan assured all. Walking out, he was asked if he had “full confidence” in Trump. Ryan paused briefly mid-stride and said, softly, “I do.”

It was a huge gamble by the top Republican in Congress. Ryan’s defense of Trump is a calculation that Trump will ride out the troubles. He is betting his political fortunes — and perhaps his party’s hold on the House — on a man who has provided very little justification for trust.

Rosenstein’s action rescues Ryan, McConnell and other GOP leaders from their own cowardice in refusing to demand more accountability from Trump.

(Victoria Walker,Jayne Orenstein,Dalton Bennett,Jenny Starrs/The Washington Post)

Trump no doubt will feel betrayed by Rosenstein, as he felt betrayed by Comey. He was already feeling awfully sorry for himself, saying Wednesday that no politician “has been treated worse or more unfairly.”

Now he is to be treated to the luxury of his own, personal special prosecutor. If past is prologue, Mueller’s investigation will be a huge distraction for the White House as everybody “lawyers up” and attention shifts from what remains of Trump’s agenda to the latest twists and turns that can be discerned. I covered the Clinton White House during the Monica Lewinsky investigation, and I don’t doubt that this probe, like that one, could prove debilitating to Trump.

But Trump’s agenda was already moribund. A mere 117 days into his presidency, Trump has already amassed a collection of scandals and failures that most presidents take years to acquire. Even before the latest debacles over Comey’s firing, his memos and Trump’s handing secrets to Russia, Trump’s political capital had been drained by the health-care woes. It’s hard to see how legislative momentum can be restored now that Washington has settled into scandal mode. Trump has the waddle of a prematurely lame duck. The Mueller appointment, at least, gives the Trump White House a chance to compartmentalize the scandals. And, crucially, it provides one more watchdog keeping Trump’s autocratic instincts from getting the better of him — and the rest of us.

These first months of the Trump administration have tested the strength of America’s democratic institutions. The good news is it appears those institutions are holding. The press has been at its best, uncovering the alarming truths about Trump’s Russia ties. Some brave patriots in intelligence and law enforcement and elsewhere in the federal government have taken risks to get the facts out. A few courageous lawmakers defied their party leaders and president. And now, finally, we see that one of Trump’s high-level appointees had the courage to defy him.

It’s often said that all that is necessary for the triumph of evil is for good men to do nothing. On Wednesday night, Rod Rosenstein did something.

Twitter: @Milbank

Read more from Dana Milbank’s archive, follow him on Twitter or subscribe to his updates on Facebook.