In her 2003 book “Treason: Liberal Treachery From the Cold War to the War on Terrorism,” conservative pundit Ann Coulter launched a full-throated defense of Joseph R. McCarthy. Hardly the witch-hunting monster of liberals’ imagination, Coulter wrote, McCarthy was a patriot who protected his country from communists overseas and their apologists at home. Coulter’s assertion reflected an enduring belief in McCarthy among the Republican faithful, who continued to lionize him long after the Senate censured the senator and ended his career in disgrace.

More than a half-century later, however, the party has abruptly changed course thanks to one man: President Trump. Instead of praising McCarthyism, Republicans use the phrase “McCarthyism” to malign Democrats who dare demand answers about Trump’s ties to Russia. Trump himself fired the first salvo in the summer, tweeting that special counsel Robert S. Mueller III’s investigation into Russian election interference was “an illegal Joseph McCarthy style Witch Hunt.” And just last week, two GOP congressional leaders compared House Intelligence Committee Chairman Adam B. Schiff (D-Calif.) — one of the investigation’s key supporters — to, yes, McCarthy.

Liberals came quickly to Schiff’s defense, noting that nothing in the Russia probe came close to the deceit and destruction of McCarthyism. But in a perverse way, these charges reflect a crucial concession by Republicans after seven decades of denial: McCarthyism was, in fact, a massive, unpardonable assault on freedom, fairness and the rule of law. And strange as it may seem, we owe that new consensus to Trump.

McCarthy’s career as a redbaiter began on Feb. 9, 1950, in Wheeling, W.Va., where he told a local Republican women’s club that there were 205 communists employed by the State Department. (The next day, on the floor of the Senate, he changed the number to 57.) It ended in 1954, when the Senate censured him. All 44 Democratic senators voted to denounce McCarthy, but the Republicans were split down the middle: 22 for and 22 against.

Even as Republicans leaders such as President Dwight Eisenhower turned against McCarthy, he remained a hero among the party’s rank and file. When he died in 1957, 25,000 people gathered to view his body before it was laid to rest in his hometown of Appleton, Wis. One local Republican newspaperman even compared McCarthy to Jesus, condemning the “thousand Pontius Pilates” who crucified McCarthy “because of his efforts to expose the communist conspiracy designed to destroy the United States.”

Over the next few years, Republicans stepped up their hero worship of McCarthy. In the 1960s, as the Vietnam War triggered protests at home, Republicans hailed the senator as a brave opponent of communism around the world. Indeed, Rep. Kenneth J. Merkel (R-Wis.) insisted, “McCarthyism” should be a respected term instead of a mark of derision. “You and I are going to have to carry on the work of the great Sen. McCarthy,” Merkel told a Republican gathering.

In 1975, when a bruised United States withdrew from Vietnam, some critics blamed the war’s outcome on a failure to follow McCarthy’s example. “If the warnings he gave had been heeded, we would have been spared many of the things happening today,” declared a GOP speaker, at a gravesite commemoration for McCarthy. “We would have a greater regard for patriotism, a willingness to defend our way of life and our freedom, and a better appreciation and love for our country.”

In the 1990s, after the Soviet Union dissolved, the release of cables between its agents and their overseas operatives unleashed a new round of Republican praise for McCarthy. There really were spies and apologists for the Soviets in America, Republicans noted, and McCarthy should be celebrated rather than vilified for exposing them.

Witness William F. Buckley Jr.’s 1999 historical novel “The Redhunter,” which depicted McCarthy as reckless, impulsive and alcoholic — and right. Back in 1954, on the eve of McCarthy’s Senate censure, Buckley and his brother-in-law L. Brent Bozell had published an entire book (“McCarthy and His Enemies”) lauding McCarthy for attacking George Marshall, Dean Acheson and other members of the foreign policy establishment. Even if these targets weren’t really communists, the argument went, they were undermining national security.

Nearly a half-century later, Buckley stood by that claim. In a 1999 interview, he insisted that McCarthy had exposed people who were “on the side of Moscow,” whether or not they were spies. Here Buckley included Johns Hopkins professor Owen Lattimore, whom McCarthy had falsely labeled “the top Soviet espionage agent in the United States.”

The pro-McCarthy view would receive another shot in the arm after the 9/11 attacks, when Coulter charged that weak-kneed liberals were again doing the bidding of America’s enemies. “Whether they are defending the Soviet Union or bleating for Saddam Hussein, liberals are always against America,” Coulter wrote. “But we can’t call them traitors, which they manifestly are, because that would be ‘McCarthyism,’ which never existed.”

To be fair, responsible conservative scholars such as Ronald Radosh noted the exaggerations and distortions in Coulter’s book. But her view still held traction on Fox News and other conservative media outlets, where McCarthy was glorified as a flawed but courageous figure.

No longer. In the past year, Trump and his supporters have engineered a sea change in Republican sentiments by invoking McCarthy — and McCarthyism — to stigmatize Trump’s critics.

Never mind that Trump has displayed some of the same reckless and vindictive qualities as McCarthy, or that Trump was also a longtime friend and client of McCarthy lawyer Roy Cohn. Those details garner the headlines and also the laugh lines, for those who enjoy irony.

But the big development has largely escaped notice: The Republican Party has finally acknowledged the evil of McCarthyism, if only to attach it to Trump’s enemies.

Mueller seems off the hook for the moment, since his report, according to Attorney General William P. Barr, didn’t establish collusion between Trump campaign members and Russia. So the GOP has focused its charges of McCarthyism upon Schiff. At an Intelligence Committee meeting last week, Rep. Michael R. Turner (R-Ohio) made the connection explicit. “With McCarthyism,” a senator was “chasing after Russian Communists,” Turner said. “Now we have Schiff chasing after Russian collusion.”

It’s too easy — and let’s face it, a lot of fun — to mock this analogy. According to historian Ellen Schrecker, between 10,000 and 12,000 Americans, including university professors, union leaders and Hollywood screenwriters, lost their jobs and couldn’t find new ones because of alleged communist affiliations. Most of them weren’t communists, and almost none of them were spies. Their lives were destroyed. No matter what you think of the Russia investigation, it’s absurd to compare an investigation of the president and his campaign to McCarthy’s excesses.

But we shouldn’t lose sight of the good news here: For the first time since the McCarthy era itself, the GOP stands united against McCarthyism. What McCarthy did was indefensible, and from now on Republicans will be reluctant to defend it. It’s too bad that it took Mueller’s investigation, and Trump’s bizarre charges against it, to make that happen.

But better late than never. The way we remember McCarthy will influence our way forward. And the new consensus on his misdeeds will make it harder for anyone, including Trump, to repeat them. At a moment of bitter partisan discord, that’s something all of us should be able to celebrate.