Then-Attorney General William P. Barr warned President Trump in April 2020 that he would lose the general election if he continued to stoke his base at the expense of appealing to independent and moderate voters. Trump replied that his campaign aides told him he would win reelection if he got 65 million votes. That meant, he implied, he didn’t need to soften his tone or move to the middle.

Trump wound up receiving 74.2 million votes. But Joe Biden got 81.2 million.

The GOP-commissioned review of Maricopa County ballots released on Friday, which confirmed Biden’s narrow victory in Arizona, is the latest reminder of the failure of Trump’s base-first strategy — but also how close it came to working. A shift of only 43,000 votes across Arizona and two other states could have delivered a second term to Trump.

Peril,” the book published last week by The Post’s Bob Woodward and Robert Costa, includes a detailed account of Barr’s Oval Office intervention. The attorney general said he heard constantly during his travels from people who liked the president’s policies but thought Trump was a huge jerk. (Barr used a more vulgar term.)

Trump told Barr that he needed to look like a fighter to mollify his base; Barr believed that picking so many senseless fights repelled the suburban women whom he saw as persuadable. “I need my base,” Trump responded. “My base wants me to be strong. These are my people.”

Barr, who declined to endorse Trump’s false claims of widespread voter fraud, left the administration before Jan. 6, but he shouldn’t be allowed to rehabilitate his reputation just because he challenged the president more forcefully than previously known. From private lawsuits to public investigations, Barr repeatedly acted more like Trump’s personal defense lawyer than the nation’s chief law enforcement officer. He alienated career prosecutors as he politicized the Justice Department, intervening on behalf of the president’s cronies and against a woman who accused Trump of sexual assault.

The attorney general is supposed to be the people’s lawyer, not the president’s consigliere, and it was inappropriate for Barr to wade so deeply into the partisan fray. But he may have been on target when he told Trump that he was too reliant on the small army of operatives who profit from keeping America’s nativist and racist extremes politically restive. “You have all these self-anointed spokespeople for your base who come and tell you what they want,” Barr said at the April 2020 meeting. “They are drowning you in their needs.”

Trump overruled Barr’s objections and demanded the Justice Department support a lawsuit brought by Texas and 17 other GOP attorneys general aimed at invalidating Obamacare. Barr saw the case as legally weak and politically toxic. But Trump was adamant they side with Texas. “That is my base,” he said, per Woodward and Costa. On a 7-to-2 vote, the Supreme Court dismissed the challenge in June. Two of the three justices nominated by Trump joined the majority.

Follow James Hohmann‘s opinionsFollowAdd

Trump also wanted an executive order that would deny citizenship to anyone born in the United States whose parents were in the country illegally. Barr said this would never survive a court test because of the 14th Amendment. Trump kept pushing to activate his nativist base. He also pressed Barr to indict former FBI director James B. Comey and others, even as Barr purportedly told him that regular voters didn’t care about this.

A registered Democrat until 2009, Trump had never been a conservative on principle, seeming instead to adopt positions that played best with right-wing populists. The most sickening illustration of this came in his response to the 2017 violence in Charlottesville when he expressed common cause with white supremacists.

As president, he closely tracked which lines got the loudest cheers at his rallies. That’s how Trump workshopped, then sharpened, his attacks against Black athletes who kneel during the national anthem. He obsessed over crowd sizes and treated arenas like focus groups. The kind of people who wait in line for hours to see Trump obviously love red meat, so he serves more of it. This toxic cycle leads to more provocation.

Even after he lost, Trump used “the base” to justify his next steps. One week after Election Day, counselor to the president Hope Hicks warned Trump that refusing to concede could tarnish his legacy. “My people expect me to fight, and if I don’t, I’ll lose ‘em,” he told her, according to “Peril.”

Months later, the cycle continues. During a meeting this summer at Trump’s New Jersey golf resort, pollster John McLaughlin presented the former president with private polling that showed 57 percent of Republicans choosing him from a field of more than a dozen other potential 2024 contenders. “The more you get attacked, the more your base gets solidified,” McLaughlin told Trump, according to the book.

If Trump had taken Barr’s advice, that meeting might have been taking place at the White House.