In a shocking turn of events, President Donald Trump abruptly terminated FBI Director James Comey late Tuesday afternoon, claiming he’d lost confidence in him. FBI staffers and many members of Congress reportedly had no idea this announcement was coming.

“President Trump acted based on the clear recommendations of both Deputy Attorney General Rod Rosenstein and Attorney General Jeff Sessions,” White House Press Secretary Sean Spicer said in a statement. A search for Comey’s replacement will begin “immediately,” Spicer said.

Just last week, Comey testified before the Senate Judiciary Committee in a hearing on Russia’s interference in the election and possible collusion between Trump officials and Russian operatives. He was scheduled to appear before a closed session of the Senate Intelligence Committee on Thursday, highlighting just how suddenly Trump’s decision came down.

The FBI is also conducting a parallel probe of Russian election meddling and potential ties between the Trump camp and Russia.

Trump informed Comey in a letter that he had lost faith in his ability to lead the intelligence agency, taking care to emphasize that Comey told him he was not a target of investigation.

“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,” Trump wrote.

In a memorandum, Deputy Attorney General Rosenstein accused Comey of causing “substantial damage” to the FBI’s “reputation and credibility” through his handling of the investigation into Hillary Clinton’s use of a private email server. Rosenstein was only confirmed by the Senate on April 25.

In the memo, he said Comey erred by announcing in a press conference on July 5 that Clinton would not be prosecuted, saying the “FBI Director is never empowered to supplant federal prosecutors and assume command of the Justice Department.”

Comey’s comments about Clinton’s “extremely careless” handling of classified information, which Republicans seized on during the 2016 presidential election, were “a textbook example of what federal prosecutors and agents are taught not to do,” Rosenstein wrote.

Rosenstein also criticized Comey’s explanation for announcing on Oct. 28, 11 days before the election, that the FBI had reopened its investigation after discovering fresh emails potentially related to the probe on a computer belonging to Anthony Weiner, the estranged husband to Clinton’s top aide Huma Abedin.

Comey testified before the Senate Judiciary Committee last week that he felt at that time that he had a choice to “speak or conceal,” and made the decision he thought best.

Rosenstein contended that not commenting on open investigations “is not concealment.”

The Justice Department’s inspector general announced in early January, prior to Trump’s inauguration, that he was investigating Comey’s public announcements about the Clinton email investigation.

Michael Horowitz said he wanted to determine if “underlying investigative decisions were based on improper considerations, among other things.”

These concerns did not prompt Trump to dismiss Comey after he took office. Asked by Fox News in April if it was a “mistake” not to ask him to step down at the outset of his presidency, Trump said it was “not too late” to do so.

“I have confidence in him,” Trump replied. “We’ll see what happens. You know, it’s going to be interesting.”

Read the White House statement, letter from Trump, letter from Attorney General Jeff Sessions, and letter from Rosenstein below.

This post has been updated.