The J. Edgar Hoover FBI Building. (Jim Lo Scalzo/European Pressphoto Agency)

THE FBI is in trouble and must be protected — from the White House, first and foremost.

Last year’s Hillary Clinton email investigation put the agency in the middle of a political fight. President Trump raised even bigger concerns for the agency’s independence when he fired Director James B. Comey on Tuesday.

At first Mr. Trump and his staff claimed he moved against Mr. Comey based on a Tuesday memo from Deputy Attorney General Rod J. Rosenstein condemning Mr. Comey’s handling of the Clinton email probe. On Thursday, Mr. Trump admitted in an NBC interview that “I was going to fire regardless of recommendation,” calling Mr. Comey a “showboat” and a “grandstander.” Reports suggest that Mr. Comey infuriated Mr. Trump with his investigation and discussion of Moscow’s meddling in the 2016 election, which helped Mr. Trump’s campaign.

Mr. Trump also claimed Thursday that he asked Mr. Comey at one point if he was the subject of an FBI investigation, and that Mr. Comey said no. If true, both the question and the answer ring alarm bells: Federal law enforcement should be insulated from all political interference and, when the administration is a subject of a probe, walled off from the White House. But Trump administration officials reportedly have prodded the FBI to prioritize investigations of alleged leaking over Russia’s hacking.

The disorderly firing process and shifting rationales have shredded what was left of this White House’s credibility. A strong chief of staff or White House Counsel’s Office would have insisted on a well-prepared and carefully defended process to remove the FBI director if that were necessary — and would have counseled against doing it at all while the director was ramping up an investigation of Mr. Trump’s campaign. Instead, Mr. Trump’s worst instincts were enabled by everyone around him.

It is essential that this White House not be allowed to export its credibility-destroying dysfunction to the Justice Department and the FBI. Attorney General Jeff Sessions promised in March not to be involved in “any matters related in any way to the campaigns for president of the United States,” a commitment already called into question by his involvement in Mr. Comey’s termination, as The Post’s Jennifer Rubin outlined Thursday. It must be clear that Mr. Rosenstein will have final say on the FBI’s Russia inquiries. The deputy attorney general was reportedly chagrined that the White House attempted to pin Mr. Comey’s firing on him. Burned once, he must protect federal law enforcement from the White House. The best way to do so in the Russia investigation would be with the appointment of a special prosecutor.

Mr. Rosenstein and the Senate, meanwhile, must ensure that those chosen to lead the FBI — either on an interim or a full-time basis — are committed to preserving the agency’s independence. During a Senate Intelligence Committee hearing Thursday, acting FBI director Andrew McCabe presented a baseline of integrity against which to judge a future nominee. Mr. McCabe said that the FBI will not update the White House on the Russia investigations and promised to tell Congress if the White House tries to interfere. By insisting that FBI staff respected Mr. Comey and that the Russia probe is “highly significant,” he implied by example that a good FBI director should have the confidence to contradict administration spin. Protecting the agency’s independence must be the next director’s mission.