Ex-FBI chief James Comey told Congress that the Trump administration’s comments about him and the FBI were “lies plain and simple”.
Mr Comey told a Senate committee they were wrong to denigrate the agency and its leadership.
He was also “confused” by the “shifting explanations” for his sacking, which came as he led a probe into any links between the Trump campaign and Moscow.
Mr Comey said Mr Trump had repeatedly told him he was doing a “great” job.
He also suggested he was fired to “change the way the Russia investigation was being conducted”.
“I know I was fired because something about the way I was conducting the Russia investigation was some way putting pressure on him, was some way irritating him,” Mr Comey said of the president.
The former FBI boss remained largely composed throughout almost three hours of testimony but became impassioned when delivering his opening remarks.
He told the panel that the White House “chose to defame me, and more importantly the FBI” by claiming the agency was “poorly led”.
“Those were lies, plain and simple. And I’m so sorry that the FBI workforce had to hear them,” he continued.
“The FBI is honest. The FBI is strong. And the FBI is and always will be independent,” he said in his opening remarks.
Mr Comey was leading one of several Russia investigations before Mr Trump fired him.
US intelligence agencies believe Russia interfered in the US election and they are investigating alleged links between the Trump campaign and Moscow.
But there is no known evidence of collusion and President Donald Trump has dismissed the story as “fake news”.
His spokeswoman Sarah Sanders on Thursday hit back at Mr Comey, saying: “I can definitively say the president is not a liar.”
For Donald Trump the good news from James Comey’s testimony is that the former FBI director clearly said the president was not directly under FBI investigation at the time he was fired. The bad news was, well, everything else.
On multiple occasions, Mr Comey said he was either concerned or knew that the president or his administration was lying “plain and simple” – about the circumstances of his dismissal and about the nature of his meetings with the president.
It’s clear the president woefully mishandled this, for which he has paid a high price ever since. By unceremoniously sacking him, and offering a muddle of explanations for it, he created an adversary with both the means and the motivation to respond in the most damaging way.
Mr Comey had a friend leak disturbing information about the president’s actions to the media. He was given the biggest spotlight in a generation to publicly air further details. He stood before a Senate committee not just to defend himself, but also the honour of the FBI.
The White House may claim today’s testimony is a technical exoneration. Politically, however, it’s a staggering blow. And when it comes to the presidency, politics is everything.
During Thursday’s testimony, Mr Comey emphasised that Russia’s political meddling was “not a close call”, adding: “There should be no fuzz on this whatsoever.”
When asked by the Senate Intelligence Committee whether the president tried to stop the Russia investigation he was conducting, Mr Comey said: “Not to my understanding, no.”
He said he it was not for him to say whether Mr Trump’s actions were an obstruction of justice.
Democratic Senator Mark Warner, the committee’s vice chairman, pressed Mr Comey on why he decided to keep record of his conversations with Mr Trump.
Mr Comey said it was a matter of circumstances, the subject matter and the “person I was interacting with”.
“I was honestly concerned that he might lie about the nature of our meeting” he told the panel of Mr Trump.
“I knew there would come a day that I might need a record, not just to defend myself, but to defend the FBI,” he said.
Mr Comey, who published his prepared remarks a day before the hearing, detailed one meeting with Mr Trump in which the president asked Attorney General Jeff Sessions and White House aide Jared Kushner to leave the Oval Office.
“I knew something was about to happen that I needed to pay very close attention to,” he said. “I remember thinking that that was a very disturbing development.”
During another meeting with Mr Trump, Mr Comey said the president appealed to him to “let go” an investigation into fired national security adviser Michael Flynn and his ties to the Kremlin.
After US media reported the conversation, the president warned Mr Comey in a tweet, saying he “better hope there are no ‘tapes’ of our conversations”.
Mr Comey told the committee he hoped there were tapes, calling on Mr Trump to release them.
“The president surely knows whether he taped me, and if he did my feelings aren’t hurt. Release all the tapes, I’m good with it,” he said.
The White House has refused to say whether any such tapes exist.
When asked how his FBI colleagues reacted to the president telling Mr Comey that he hoped the investigation into Mr Flynn would be dropped, he said: “I think they were as shocked and troubled as I was.”
“They’re all experienced professionals and they had never experienced such a thing,” he said.
“The conversation turned to what we should do about it and that was a struggle for us.”
After Mr Trump’s tweet about potential tapes, Mr Comey said he realised it was important to release his own account of the story.
He revealed that he asked a “good friend of mine” who is a professor at Columbia Law School to share contents of the memo with a reporter.
Mr Comey added that he asked for the documents to be leaked in order to build pressure for a special counsel.
As a result of this episode, former FBI chief Robert Mueller was appointed as special counsel to lead an independent investigation into the Trump campaign’s potential ties to the Kremlin.
Mr Comey said he was “sure” Mr Mueller was also looking at whether Mr Trump obstructed justice.