The Post’s Matt Zapotosky explains why FBI Director James B. Comey has found himself at the center of the presidential campaign in recent days. (Bastien Inzaurralde/The Washington Post)

Deep divisions inside the FBI and the Justice Department over how to handle investigations dealing with Hillary Clinton will probably fester even after Tuesday’s presidential election and pose a significant test for James B. Comey’s leadership of the nation’s chief law enforcement agency.

The internal dissension has exploded into public view recently with leaks to reporters about a feud over the Clinton Foundation, an extraordinary airing of the agency’s infighting that comes as the bureau deals with an ongoing threat of terror at home and a newly aggressive posture from Russia.

Comey, meanwhile, has come under direct fire for his decision to tell Congress that agents were resuming their investigation of Clinton’s use of a private email server — a revelation that put him at odds with his Justice Department bosses and influenced the presidential campaign.

“He’s got to get control of the ship again,” said Robert Anderson, a former senior official in the FBI who considers Comey a friend. “There’s a lot of tension in the organization, and there’s a lot of tension in Congress and the Senate right now, and all that counts toward how much people trust the FBI.”

The Post’s Rosalind Helderman breaks down the latest developments of the controversies involving the FBI less than a week from Election Day. (Bastien Inzaurralde/The Washington Post)

Comey has been under fire since Friday from lawmakers in both parties and even President Obama for his decision to inform Congress of the new developments in the email probe just 11 days before Election Day. On Thursday, people familiar with the matter told The Washington Post that Comey had learned three weeks earlier of the discovery of new emails potentially relevant to the case, but did not take action to resume the email probe until he was formally briefed last week on what investigators had found.

Clinton, who seemed to have momentum in battleground state polls before Comey’s Friday bombshell, notably declined on Thursday to say whether, if elected, she would ask the FBI director to resign.

“I’m not going to, you know, either get ahead of myself by assuming I’ll be fortunate enough to be elected,” Clinton said, responding to a question from SiriusXM’s Joe Madison. “That’s really up to you and your listeners. People have to turn out, or nothing that I’m going to be proposing will come into reality, but I also would never comment on any kind of, you know, personnel issue.”

Comey was confirmed to a 10-year term in September 2013. While the law allows a president to remove an FBI director, the step is rarely taken out of respect for the independence of the position. President Bill Clinton removed Director William S. Sessions in 1993 amid allegations of ethical improprieties.

The pent-up frustration inside the FBI seemed to burst when Comey revealed in a brief letter to legislators that agents in an unrelated case had found emails potentially relevant to the Clinton email investigation.

The details, then and now, were scant. Officials familiar with the matter said the messages came from a computer seized in the investigation of disgraced former congressman Anthony Weiner (D-N.Y.), the estranged husband of top Clinton aide Huma Abedin. Agents said the messages were associated with Abedin and Clinton. Abedin has told people she has no idea how the messages got on the device.

Although investigators had discovered the emails in early October, software glitches prevented them from separating Abedin-related emails from the hundreds of thousands of messages recovered until Oct. 19 or 20, according to people familiar with the case.

While Comey had been quickly alerted by his deputy to the original find, he took no further action, allowing agents in the field to get a better idea of the scope of the material. Agents could use digital clues to decipher where emails had originated and been sent but were legally barred from reading the emails without a search warrant because they had been obtained in a separate investigation.

When agents formally recommended on Oct. 27 that the warrant be sought, Comey agreed and then felt obligated to inform Congress — which he did with his letter the following day. Comey’s only reference in the letter to the timing of his involvement was that he had been briefed the previous day.

FBI spokesmen declined to comment on the timeline of Comey’s knowledge or on internal tensions.

The FBI obtained a warrant Sunday to analyze the messages for the Clinton investigation. It remains unclear if any of the newly discovered emails contain classified or other relevant information.

Comey had previously said he recommended that the Clinton email case be closed without charges.

Not long after Comey’s new letter to Congress was made public last week, multiple media outlets reported that he had sent the missive against the advice of top Justice Department officials, who felt that commenting publicly on the inquiry would violate a long-standing policy not to take overt steps in investigations that could have an impact so close to an election. Before the weekend was over, the Wall Street Journal revealed there was a different, ongoing feud between FBI agents in New York and career public integrity prosecutors at the Justice Department over whether there was cause to investigate the Clinton Foundation.

Addressing the controversy in an interview posted Wednesday by NowThis News, Obama hinted that he was unhappy about the amount of information being revealed.

“I do think that there is a norm that when there are investigations we don’t operate on innuendo, and we don’t operate on incomplete information, and we don’t operate on leaks,” he said.

Tensions had been thick between New York and Washington for months, dating to disagreements over how to handle the case of Eric Garner, the 43-year-old black man who died after being put in an apparent chokehold by a police officer. Officials in the Justice Department’s civil rights division wanted to move forward with a case against the police officer, but New York-based agents and prosecutors vehemently disagreed, according to people familiar with the case. The attorney general has yet to resolve the dispute.

In the case of the Clinton Foundation inquiry, it was the FBI agents pushing for stronger action.

In February, people familiar with the case said, agents made their case to public integrity prosecutors about why they should proceed with a probe looking broadly at whether donors to the Clinton family charity were given improper benefits by the Hillary Clinton-led State Department.

Justice Department attorneys and FBI officials in Washington viewed the agents’ presentation as lacking substantive evidence. The attorneys felt it relied too heavily on public reports and the book “Clinton Cash,” and denied the agents authority to move forward, according to people familiar with the discussions. The 2015 book, by conservative author Peter Schweizer, relied heavily on public records and presented a largely circumstantial case that State Department actions were driven by donations to the Clinton Foundation and payments to Bill Clinton.

The move frustrated some agents in New York. They felt they were being stymied by Justice Department higher-ups in Washington and pressed forward in ways they felt were permissible, according to people familiar with the case. In August, a Justice Department official got wind of those efforts and called a counterpart in the FBI to inquire about it, one of the people said. The agents thought they had reason to believe they should press forward, although their leaders were warned that they should not take any steps close to the election, the person said.

The people familiar with the matters declined to discuss the precise evidence that agents had obtained. The Wall Street Journal reported Wednesday that their work involved informants and recordings from unrelated corruption investigations.

Officials speaking with reporters on the condition of anonymity is common, and several did so for this report. But the level of specificity that has emerged in recent days about a politically sensitive investigation on the eve of an election is unusual — a sign of the deep tensions inside the Justice Department.

A spokeswoman for the FBI’s New York field office and spokesmen for the Justice Department and FBI headquarters declined to comment for this report. FBI Agents Association President Thomas F. O’Connor said in a statement: “Agents undertake all investigations with an unwavering focus on complying with the law and the Constitution, and perform their mission with integrity and professionalism. Any implication that Agents are unwilling or incapable of performing effective investigations — or implications that Agents do not respect the confidentiality of those investigations — is simply false.”

If Clinton is elected, Comey might have to contend with one or more investigations involving a sitting president. If she is not, he might face criticism for upending her bid.

Anderson, the former FBI official, said Comey will have to work quickly to finish the restarted email review, then talk to leaders and visit field offices to ease the tensions in the bureau and help mend public perceptions of the FBI. Comey has repeatedly said in the past that is important to him.

“I don’t know what your parents taught you, but mine always taught me you can’t care what people think about you. I do,” he said at a recent conference to mark the 10th anniversary of the Justice’s Department’s National Security Division. “I do because the institution I’m lucky enough to lead depends upon the American people believing that we are honest, competent and independent.”