Jeff Sessions served his president poorly, and he served his country worse.

The attorney general testified for three hours Tuesday on Capitol Hill, attempting to refute every attack on his judgment and integrity. But on the issue that mattered most — his role in the firing of former FBI director James Comey — he shamed himself.

EDITORIAL

When President Donald Trump fired Comey on May 9, the whole country, save a few ostriches with their heads in the sand, knew exactly why. Trump was furious that Comey refused to kill an investigation into his former national security adviser, Michael Flynn.

But Sessions, it is obvious now, did his best to give Trump a cover story. He produced a letter, in cooperation with Deputy Attorney General Rod J. Rosenstein, that recommended Comey be canned for fumbling an investigation into Hillary Clinton’s emails. Trump cited the letter in firing Comey.

The cover story blew up, of course. Trump can never stick to a script. The day after he fired Comey, the president bragged about it, telling two Russian visitors to the Oval Office, “I faced great pressure because of Russia. That’s taken off.”

In a TV interview the day after that, Trump abandoned his cover story altogether, saying he had planned to fire Comey anyway because “this Russia thing with Trump and Russia is a made-up story.”

On Tuesday, testifying before the Senate Intelligence Committee, Sessions insisted that Trump’s full grounds for firing Comey were beside the point. The president asked him to write the letter, he said, so he did.

But that defense falls apart in two ways.

To begin with, Sessions never had a problem with Comey until the FBI began looking into Russian interference in the November election, including the possibility of collusion by the Trump campaign. On the contrary, Sessions adored Comey when he was targeting Clinton.

Secondly, it does not matter that Sessions honestly may have soured on Comey. If he suspected Trump’s motive in firing the FBI director was even partially to derail the FBI’s investigation, he failed in his duty to his country by helping the president concoct a cover story.

Mixed motives don’t excuse obstruction of justice.

With respect to this last point, it helps to recall what Trump tweeted less than 24 hours before he dumped Comey: “The Russia-Trump collusion story is a total hoax, when will this taxpayer funded charade end?”

Sessions, an influential senator for 20 years, is nobody’s fool. As his testimony Tuesday revealed — as much in what he did not say as in what he did — he knew the score when he provided Trump an excuse to fire Comey.

Sen. Jack Reed, D-Rhode Island, saw the problem clearly.

“Did you feel misled,” he asked Sessions, “when the president announced that his real reason for dismissing Mr. Comey was the Russia investigation?”

“I’m not able to characterize that fact,” Sessions replied. “I wouldn’t try to comment on that.”

Reed bore in: “So you had no inkling that there was anything to do with Russia until the president of the United States basically declared not only on TV but in the Oval Office to the Russian foreign minister, saying, ‘The pressure is off now. I got rid of that nutjob.’ That came to you as a complete surprise?”

Sessions ducked again: “Well, all I can say, Sen. Reed, that our recommendation was put in writing and I believe it was correct and I believe the president valued it, but how he made his decision was his process.”

Reed tried one more time: “And you had no inkling that he was considering the Russia investigation?”

The attorney general again declined to answer, which said everything.

Sessions later said he thinks it’s important to get to the bottom of the Russia hacking scandal.

Let the record show he did his small part to keep that from happening.