US President Donald Trump has "terminated" FBI director James Comey with the top US law enforcement official ousted while he was speaking to agents.
The firing came as the FBI investigated whether Mr Trump's campaign had ties to Russia's meddling in the election that sent him to the White House.
In a letter to Mr Comey, Mr Trump said the sacking was necessary to restore "public trust and confidence" in the FBI, but his political opponents were quick to compare the president's actions to those of one of his predecessors, Richard Nixon, during the Watergate affair that eventually toppled him.
In an early-morning tweet on Wednesday, Mr Trump added that Mr Comey "will be replaced by someone who will do a far better job, bringing back the spirit and prestige of the FBI".
He also attacked Democrats who were critical of his firing of Mr Comey.
Mr Trump said that 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!".
The president said that Republicans and Democrats will soon "be thanking me" for firing Mr Comey.
He tweeted that Mr Comey had "lost the confidence of almost everyone in Washington, Republican and Democrat alike", adding that "when things calm down, they will be thanking me!",
Mr Comey has come under intense scrutiny in recent months for his public comments on an investigation into Democrat Hillary Clinton's email practices, including a pair of letters he sent to Congress on the matter in the closing days of last year's campaign.
Mr Trump made no mention of Mr Comey's role in the Clinton investigation, which she has blamed in part for the election result.
But in announcing the firing, the White House circulated a scathing memo, written by Deputy Attorney General Rod Rosenstein, criticising Mr Comey's handling of the Clinton probe, including the director's decision to hold a news conference announcing its findings and releasing "derogatory information" about Mrs Clinton.
Since Attorney General Jeff Sessions recused himself from the bureau's Trump-Russia probe, Mr Rosenstein has been in charge.
This is only the second firing of an FBI director in history with president Bill Clinton dismissing William Sessions amid allegations of ethical lapses in 1993.
Mr Comey was speaking to agents at the FBI's field office in Los Angeles when the news of his firing flashed on TV screens, according to a law enforcement official who was there.
James Comey will be replaced by someone who will do a far better job, bringing back the spirit and prestige of the FBI.— Donald J. Trump (@realDonaldTrump) May 10, 2017
Mr Comey initially chuckled, then finished his speech, said the official, before he left on a plane to return to Washington.
Democrats slammed Mr Trump's action, comparing it to Mr Nixon's Saturday Night Massacre decision to fire the independent special prosecutor overseeing the Watergate investigation in 1973, which prompted the resignations of the Justice Department's top two officials.
The Democrats expressed deep scepticism about the stated reasons for Tuesday's firing, raising the prospect of a White House effort to frustrate the investigations by the FBI and congressional panels.
"This is Nixonian," Senator Bob Casey declared on Twitter.
Republican Senator John McCain of Arizona said Congress must form a special committee to investigate Russia's interference in the election.
Mr Trump will now appoint Mr Comey's successor while his deputy, Andrew McCabe, takes over in the interim.
Mr Trump has ridiculed the investigations as a "hoax" and has denied his campaign was involved in Russia's meddling.
In his letter to Mr Comey, he asserted that the FBI director had informed him "on three separate occasions that I am not under investigation".
Tuesday's stunning announcement came shortly after the FBI corrected aspects of Mr Comey's sworn testimony on Capitol Hill last week.
Comey lost the confidence of almost everyone in Washington, Republican and Democrat alike. When things calm down, they will be thanking me!— Donald J. Trump (@realDonaldTrump) May 10, 2017
Mr Comey told politicians Huma Abedin, a top aide to Hillary Clinton, had sent "hundreds and thousands" of emails to her husband's laptop, including some with classified information.
On Tuesday, the FBI told the Senate Judiciary Committee only "a small number" of the thousands of emails found on the laptop had been forwarded there while most had simply been backed up from electronic devices.
Most of the email chains on the laptop containing classified information were not the result of forwarding, the FBI said.
Some politicians did welcome news of the dismissal.
"Given the recent controversies surrounding the director, I believe a fresh start will serve the FBI and the nation well," said Republican Lindsay Graham of South Carolina, chairman of a Senate Judiciary subcommittee investigating the Russian campaign interference.
Mr Comey, 56, was nominated by President Barack Obama for the FBI post in 2013 to a 10-year term, though that appointment does not ensure a director will serve the full term.
His prominent role in the 2016 presidential campaign raised questions about his judgment and impartiality.
Though the FBI did not recommend charges against Mrs Clinton for mishandling classified information, Mr Comey was blisteringly critical of her decision to use a personal email account and private internet server during her four years as secretary of state.
Mr Comey strongly defended his decisions during the hearing last week.
He said he was "mildly nauseous" at the thought of having swayed the election but also said he would do the same again.
Mrs Clinton has partially blamed her loss on Mr Comey's disclosure to Congress less than two weeks before Election Day that the email investigation would be revisited.
Mr Comey later said the FBI, again, had found no reason to bring any charges.
Mr Trump disagreed with Mrs Clinton's assessment, tweeting Mr Comey actually "was the best thing that ever happened to Hillary Clinton in that he gave her a free pass for many bad deeds!".
Mrs Clinton's advisers were stunned by Mr Trump's decision.
Former campaign spokesman Brian Fallon said, while he believed Mr Comey had "inflicted severe damage" on the FBI, "the timing and manner of this firing suggest that it is the product of Donald Trump feeling the heat on the ongoing Russia investigation and not a well thought out response to the inappropriate handling of the Clinton investigation".
Though Mr Comey was well-liked within the bureau, his independent streak occasionally rankled the Obama administration, including his repeated contention a spike in violent crime might be linked to police officer anxiety over public scrutiny.
Before the past months' controversies, Mr Comey, a former deputy attorney general in the George W Bush administration, was perhaps best known for a remarkable 2004 stand-off with top officials over a federal domestic surveillance programme.
In March of that year, Mr Comey rushed to the hospital bed of attorney general John Ashcroft to physically stop White House officials in their bid to get his ailing boss to reauthorise a secret no-warrant wire-tapping programme.
Mr Comey described the incident in 2007 testimony to Congress, explaining he believed the spy programme put in place after the September 11 2001 terror attacks was legally questionable.