Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

President Donald Trump fired FBI Director James Comey on Tuesday after senior Justice Department officials concluded that he'd mishandled the investigation of Hillary Clinton's use of a private email server while she was secretary of state.

"You are hereby terminated and removed from office, effective immediately," Trump told Comey in a personally signed letter obtained by NBC News.

Deputy FBI Director Andy McCabe will take over temporarily as acting director, Attorney General Jeff Sessions told FBI employees in a message obtained by NBC News.

White House Press Secretary Sean Spicer said in a statement that Trump acted "on the clear recommendations" of Sessions and Deputy Attorney General Rod Rosenstein. He said a search for a new FBI director would begin "immediately."

The FBI has been investigating allegations that people involved with Trump's presidential campaign had undisclosed ties to Russia. But during a brief meeting with NBC News in the Oval Office on Tuesday evening, Trump said the Russia probe wasn't a factor in his decision.

The distinction is crucial, because Sessions signed off on Comey's dismissal even though he has recused himself from involvement in the investigation of Russia's ties to the presidential campaign.

Related: Timeline: Former FBI Director James Comey's Fall From Grace

Trump said that while he'd had concerns about Comey for some time, it was the FBI's "clarification" of Comey's inaccurate Senate testimony last week about Clinton's email practices that raised new questions about the director's competence and judgment.

Deputy White House Press Secretary Sarah Huckabee Sanders told reporters Tuesday night that Comey's inaccurate Senate testimony last week "showed that he was incapable of continuing to do his job."

"Here's the bottom line: Comey had lost the confidence across the board, from House members, from Senate members, from rank-and-file members of the FBI and the American public," Sanders said.

In his letter to Comey, the president wrote: "While I greatly appreciate your informing me, on three 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."

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Independent counsel demanded

Republicans and Democrats alike said the dismissal called the FBI's independence into question, and many Democrats immediately called for appointment of an independent counsel to take over the Russia investigation.

Related: Democrats Charge Comey Firing 'Nixonian,' Demand Special Prosecutor

"Everyone will suspect [a] coverup" otherwise, Senate Democratic leader Chuck Schumer of New York said at a hastily called news conference.

The president responded on his personal Twitter account Tuesday night, saying Schumer himself had "recently" said he had no confidence in Comey.

Cryin' Chuck Schumer stated recently, "I do not have confidence in him (James Comey) any longer." Then acts so indignant. #draintheswamp — Donald J. Trump (@realDonaldTrump) May 10, 2017

In an interview with Bloomberg News in November, Schumer said it was "appalling" that Comey disclosed new developments in the FBI's investigation of Clinton's email practices shortly before Election Day.

"I do not have confidence in him any longer," he said at the time.

Comey 'shocked' by surprise firing

The White House said the dismissal had already been in the works before the FBI acknowledged Comey's inaccurate testimony. But three senior FBI and Justice Department officials told NBC News that Comey was given no warning.

Federal officials said Comey was in the FBI's Los Angeles operations center when he got a call notifying him that he had been fired. Employees in the office, aware of the news reports, gathered outside the center and gave him an ovation as he came out.

Senior FBI officials who convened a conference call afterward were described as "stunned," officials told NBC News. They said Comey himself was "shocked."

Related: FBI Issues Clarification on Comey Testimony of Huma Abedin Emails

In his recommendation to fire Comey, also obtained by NBC News, Rosenstein specifically told Trump that Comey mishandled the overall investigation of the email scandal and that he was wrong to have announced last July that the Justice Department's investigation of Clinton's emails was being closed.

Referring to Comey's statement on Oct. 28 that more Clinton emails had been found on a laptop computer belonging to Anthony Weiner, the husband of top Clinton aide Huma Abedin, Rosenstein wrote: "We do not hold press conferences to release derogatory information about the subject of a declined criminal investigation."

"The FBI Director is never empowered to supplant federal prosecutors and assume command of the Justice Department," he wrote. "The way the Director handled the conclusion of the email investigation was wrong."

Sen. Chuck Grassley, R-Iowa, chairman of the Judiciary Committee, said in a statement: "The effectiveness of the FBI depends upon the public trust and confidence. Unfortunately, this has clearly been lost."

But Sen. Patrick Leahy of Vermont, a Democrat on the committee, called the move "shocking."

"No one should accept President Trump's absurd justification that he is now concerned that FBI Director Comey treated Secretary Clinton unfairly," Leahy said in a statement. "This is nothing less than Nixonian."

Rep. John Conyers of Michigan, ranking Democrat on the Judiciary Committee, and the ranking Democrats on five Judiciary subcommittees sent a letter to Rosenstein and McCabe on Tuesday night demanding that the Justice Department and the FBI preserve all documents relating to both Comey's dismissal and the Russia investigation.

"The Trump administration cannot be allowed to interfere any further in this investigation," they wrote, adding: "Nothing less than the integrity of our leading independent law enforcement agency and the credibility of our democracy are at stake."

Representatives of Clinton and former President Barack Obama said they had no immediate comment. But other Democrats calling for an independent investigation of the Trump campaign's alleged Russia ties included Sens. Kirsten Gillibrand of New York, Bill Nelson of Florida and Jeff Merkley of Oregon.

In case the need for an independent special prosecutor to investigate #TrumpRussia ties wasn’t clear enough already… it sure is now. https://t.co/G3yoovqi0a — Senator Jeff Merkley (@SenJeffMerkley) May 9, 2017

Even as those calls mounted, the White House confirmed Tuesday night that the president would meet with Russian Foreign Minister Sergey Lavrov in the Oval Office on Wednesday.

While the president has the legal authority to fire the FBI director, it has happened only once before, in 1993, when President Bill Clinton dismissed William Sessions after an internal watchdog found that he had improperly billed the FBI for personal spending.