President Trump fired FBI Director James B. Comey on Tuesday, at the recommendation of senior Justice Department officials who said he had treated Hillary Clinton unfairly and in doing so damaged the credibility of the FBI and the Justice Department.

The startling development comes as Comey was leading a counterintelligence investigation to determine whether associates of Trump may have coordinated with Russia to interfere with the U.S. presidential election last year. It wasn’t immediately clear how Comey’s ouster will affect the Russia probe, but Democrats said they were concerned that his ouster could derail the investigation.

[How members of Congress reacted after Comey’s dismissal]

Attorney General Jeff Sessions announced that Comey’s deputy, Andrew McCabe, would be the acting director of the FBI. As a presidential candidate, Trump explicitly criticized Comey and McCabe for their roles in the Clinton probe while at other points praising Comey for his “guts.”

“The president has accepted the recommendation of the attorney general and the deputy attorney general regarding the dismissal of the director of the Federal Bureau of Investigation,” press secretary Sean Spicer told reporters in the White House briefing room. The firing is effective “immediately,” he said.

(Victoria Walker/The Washington Post)

On Wednesday, Trump shot back at Democrats outraged by Comey’s firing, but did not give further details on the White House decision.

“The Democrats have said some of the worst things about James Comey, including the fact that he should be fired, but now they play so sad!” Trump wrote in a Twitter post.

In a separate tweet, Trump said Comey had “lost the confidence of almost everyone in Washington, Republican and Democrat alike.”

“When things calm down, they will be thanking me!” Trump wrote.

Trump also defended his action by claiming Comey would be “replaced by someone who will do a far better job” and restore “the spirit and prestige of the FBI.”

Comey was in Los Angeles on Tuesday on a recruiting trip.

Officials said Comey was fired because senior Justice Department officials concluded that he had violated Justice Department principles and procedures last year by publicly discussing the investigation of Hillary Clinton’s use of a private email server. Democrats have long argued that Comey’s decisions in the months and days before the election hurt Clinton’s standing with voters and affected the outcome, but the president and his closest advisers had argued that Comey went too easy on Clinton and her aides.

1 of 22 Full Screen Autoplay Close Skip Ad × The career of James B. Comey as FBI director View Photos James Comey, the head of the bureau since 2013, was dismissed by President Trump on May 9, 2017. Caption James B. Comey, the head of the bureau since 2013, was dismissed by President Trump on May 9, 2017. March 15, 2017 FBI Director James B. Comey leaves a closed-door meeting with senators about President Trump’s allegations of wiretapping at Trump Tower during the 2016 election at the Capitol in Washington. Justin Sullivan/Getty Images Buy Photo Wait 1 second to continue.

Just last week, Trump publicly accused Comey of giving Clinton “a free pass for many bad deeds’’ when he decided not to recommend criminal charges in the case.

Officials released a Tuesday memo from the deputy attorney general, Rod J. Rosenstein, laying out the rationale behind Comey’s dismissal and attributing it all to his handling of the Clinton case. Officials said Rosenstein began examining Comey’s conduct shortly after being sworn into office two weeks ago.

[The Justice Department’s case against James B. Comey, annotated]

“The FBI’s reputation and credibility have suffered substantial damage, and it has affected the entire Department of Justice,” Rosenstein wrote. “I cannot defend the director’s handling of the conclusion of the investigation of Secretary Clinton’s emails, and I do not understand his refusal to accept the nearly universal judgment that he was mistaken. Almost everyone agrees that the director made serious mistakes; it is one of the few issues that unites people of diverse perspectives.”

Democrats skeptical

But Democrats immediately linked the dismissal to the Russia probe.

“The decision by a President whose campaign associates are under investigation by the FBI for collusion with Russia to fire the man overseeing that investigation, upon the recommendation of an Attorney General who has recused himself from that investigation, raises profound questions about whether the White House is brazenly interfering in a criminal matter,” Rep. Adam B. Schiff (Calif.), the ranking Democrat on the House Intelligence Committee, said in a statement. The House committee is looking into Russian interference in the election.

Some Republicans were also concerned. “I am troubled by the timing and reasoning of Director Comey’s termination,” said Sen. Richard Burr (R-N.C.), head of the Senate Intelligence Committee, which is also examining Russian meddling. “I have found Director Comey to be a public servant of the highest order, and his dismissal further confuses an already difficult investigation by the Committee.”

There were multiple calls by Democrats on Tuesday night for the appointment of a special prosecutor to lead the Russia investigation and take the matter out of the hands of Justice Department leadership.

In an attempt to pressure Republicans to join calls for an independent prosecutor, Senate Democrats have been asked by Minority Leader Charles E. Schumer (D-N.Y.) to be in the Senate chamber at 9:30 a.m. Wednesday when the legislative day begins.

In a late-night tweet Tuesday, Trump targeted Schumer. “Cryin’ Chuck Schumer stated recently, “I do not have confidence in him (James Comey) any longer.” Then acts so indignant. #draintheswamp,” the president wrote.

Trump plans to meet with Russian Foreign Minister Sergei Lavrov on Wednesday. It will be the first face-to-face contact between the president and a senior official of the Russian government.

[James Comey timeline: Everything that led up to his firing]

Rosenstein wrote in the memo that when Comey announced on July 5 that he had decided not to recommend charges in the Clinton case, he did so “without the authorization of duly appointed Justice Department leaders. Compounding the error, the director ignored another long-standing principle: we do not hold news conferences to release derogatory information about the subject of a declined criminal investigation . . . we never release it gratuitously . . . It is a textbook example of what federal prosecutors and agents are taught not to do.”

Rosenstein was also critical of Comey’s decision to reveal in late October that the Clinton email probe had resumed, and he dismissed the FBI director’s recent defense to Congress that not doing so would have effectively been to “conceal” important information.

“ ‘Conceal’ is a loaded term that misstates the issue,” Rosenstein wrote. “When federal agents and prosecutors quietly open a criminal investigation, we are not concealing anything; we are simply following the long-standing policy that we refrain from publicizing non-public information. In that context, silence is not concealment.”

In a letter to Trump, Sessions said that he agreed Comey had to go.

“I have concluded that a fresh start is needed at the leadership of the FBI,’’ Sessions wrote. “I must recommend that you remove Director James B. Comey, Jr. and identify an experienced and qualified individual to lead the great men and women of the FBI.’’

But in October — when Sessions was a senator supporting Trump, and Comey revealed less than two weeks before the election that he had reopened the investigation into Clinton’s use of a private email server — Sessions applauded the decision in an appearance on Fox Business Network.

“He had an absolute duty, in my opinion, 11 days or not, to come forward with the new information that he has and let the American people know that, too,” Sessions said at the time.

Nothing in the Rosenstein memo suggests that the Clinton investigation will be reopened.

Tuesday afternoon, White House aide Keith Schiller, who has long served Trump as a bodyguard, visited FBI headquarters to hand-deliver Trump’s dismissal letter to Comey’s office, although the director wasn’t there to receive it, officials said.

Trump wrote to Comey: “You are hereby terminated and removed from office, effective immediately.’’

[Read the letters from the White House and the attorney general]

The president added: “While I greatly appreciate you informing me, on three separate occasions, that I am not under investigation, I nevertheless concur with the judgment of the Department of Justice that you are not able to effectively lead the Bureau.’’

Speaking to reporters Tuesday evening, Spicer said he did not know what the three occasions were when Comey told Trump that he wasn’t under investigation. Spicer also rejected calls for a special prosecutor. “Special prosecutor, for what? On multiple occasions, they said that the president wasn’t under investigation. What are we investigating?” he said.

The news of Comey’s firing stunned Washington.

Sen. Charles E. Grassley (R-Iowa), chairman of the Senate Judiciary Committee, said Comey’s decisions “have called into question the trust and political independence of the FBI.’’

The senior Democrat on the House Judiciary Committee, Rep. John Conyers Jr. (Mich.), however, compared Tuesday’s developments to the Watergate scandal and said the actions “reek of a coverup and appear to be part of an ongoing effort by the Trump White House to impede the investigation into Russian ties and interference in our elections.’’

Over the past two years, Comey had assumed an extraordinary role in Washington — overseeing not one, but two investigations involving presidential candidates. In some ways, that made him more powerful than the Justice Department officials to whom he reported.

After Clinton lost to Trump, many Democrats blamed Comey for what they viewed as his unprecedented interference in the election process, but most later came to see him as an independent figure in the Trump administration who would be critical to a fair and thorough investigation of any possible ties between Russia and Trump associates.

Strains over leak cases

Several current and former officials said the relationship between the White House and the FBI had been strained for months, in part because administration officials were pressuring Comey to more aggressively pursue leak investigations over disclosures that embarrassed the White House and raised questions about ties with Russia.

That pressure was described as conversational challenges to FBI leadership to pursue the source of leaks seen as damaging to the administration, the officials said, speaking on the condition of anonymity to discuss internal deliberations. Although the FBI is investigating disclosures of classified information, the bureau has resisted calls to prioritize leak investigations over the Russia matter, or probe matters that did not involve leaks of classified or otherwise sensitive information, the officials said.

[Comey’s removal sparks fears about future of Russia probe]

“The administration has been putting pressure on the FBI to focus more on the leaks and weren’t satisfied with the results,’’ said a former senior U.S. official familiar with the matter. A current official said administration figures have been “very aggressive’’ in pressuring the FBI.

The Justice Department inspector general has been investigating how Comey and his top deputy handled the Clinton probe, though that investigation is expected to continue for months.

Shortly before the announcement, the FBI notified Congress by letter that Comey had misstated key findings involving the Clinton email investigation during testimony last week, but nothing about that issue suggested it might imperil Comey’s job.

David Weigel, Ed O’Keefe, Jenna Johnson, Ellen Nakashima and Brian Murphy contributed to this report.

Read more:

Here’s how unusual it is for an FBI director to be fired

Tuesday night firing of Comey: ‘Nixonian’ or uniquely Trumpian?

The attorney general could have ordered FBI Director James B. Comey not to send his bombshell letter on Clinton emails. Here’s why she didn’t.