In riveting testimony before U.S. lawmakers, former FBI director James Comey said that he was fired because of the investigation he was conducting into the President's advisers and accused Donald Trump of lying about the reasons for his dismissal.

Mr. Comey said his interactions with Mr. Trump in the first months of the new administration left him "stunned" and "troubled" as the President sought to undermine the traditional independence of the FBI and its work. Now the question for investigators, the American public and members of Congress is whether Mr. Trump's behaviour was simply inappropriate or potentially against the law.

Thursday's hearing marked the first opportunity since his dismissal on May 9 for Mr. Comey to tell his story to the public. In matter-of-fact terms, he expanded on earlier reports of tense encounters with the President.

Story continues below advertisement

Read more: Comey speaks: What you missed from his Senate testimony on Trump and the Russia probe

Sarah Kendzior: Comey testimony reveals Trump is running America like a crime boss

At an awkward private dinner in January, for instance, Mr. Comey said, Mr. Trump asked the FBI director for his "loyalty" but Mr. Comey demurred. At the White House in February, Mr. Trump told his advisers to leave so he could be alone with Mr. Comey in the Oval Office. Mr. Comey said Mr. Trump then told him, "I hope you can let this go," in reference to an investigation into Michael Flynn, the former national security adviser.

"I took it as a direction," Mr. Comey said Thursday.

"I mean, this is the President of the United States, with me alone, saying 'I hope' this. I took it as 'This is what he wants me to do,'" Mr. Comey said.

Under questioning from senators on Thursday, Mr. Comey repeatedly underscored the depth of his concerns about Mr. Trump. The former FBI director said he began taking notes after meetings with Mr. Trump because he feared the President would lie about those conversations.

Mr. Comey passed one of those memos to the media via a friend in May in the hope that it would help spur the appointment of a special counsel. Soon after, the Justice Department appointed Robert Mueller to that role.

Story continues below advertisement

In the most emotional moment of his testimony, Mr. Comey shot back at Mr. Trump for claiming that he fired the FBI director for doing a poor job and losing the confidence of the agency's employees. The administration "chose to defame me and, more importantly, the FBI," said Mr. Comey. "Those were lies, plain and simple."

Now Mr. Trump and Republicans face a battle to influence public perception of Mr. Comey's testimony. In a statement, Mr. Trump's private counsel, Marc Kasowitz, said that the President was vindicated by Mr. Comey's statements that Mr. Trump himself was not under investigation.

Mr. Kasowitz said the President never sought to "impede the investigation into attempted Russian interference in the 2016 election" and "never in form or substance directed or suggested that Mr. Comey stop investigating anyone."

Paul Ryan, the Republican speaker of the House of Representatives, presented Mr. Trump's behaviour as the product of inexperience. Mr. Trump is "new to government," Mr. Ryan said. "He probably wasn't steeped in the long-running protocols" governing the relationship between the White House and law-enforcement authorities.

Mr. Comey, a former prosecutor with a reputation for integrity, made clear that he believed the continuing investigation into possible collusion between advisers to Mr. Trump and the Kremlin was the cause of his dismissal.

"There's no doubt … that I was fired because of the Russia investigation. I was fired in some way to change, or the endeavour was to change, the way the Russia investigation was being conducted," Mr. Comey said. "That is a very big deal … the nature of the FBI, and the nature of its work, requires that it not be the subject of political consideration."

Story continues below advertisement

Initially, Trump administration officials linked Mr. Comey's dismissal to his handling of the inquiry into former secretary of state Hillary Clinton's use of a private e-mail server. Mr. Comey said last year that no charges were warranted in the probe. Then, during the last weeks of the election campaign, he set off a firestorm by telling lawmakers that investigators were examining a fresh set of e-mails, which subsequently were determined to be insignificant.

On Thursday, Mr. Comey also challenged Mr. Trump to make good on a veiled threat to release recordings of their meetings. When details of Mr. Comey's conversations with the President emerged in the media last month, Mr. Trump wrote on Twitter: "James Comey better hope that there are no 'tapes' of our conversations before he starts leaking to the press!"

At one point during his testimony, Mr. Comey said: "Lordy, I hope there are tapes." Later, he added: "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."

Mr. Comey sidestepped questions about whether he believed that Mr. Trump's pattern of behaviour amounted to obstruction of justice. "I don't know," he said in response to a question from Senator Joe Manchin of West Virginia. It is the job of Mr. Mueller, the special counsel, he said, "to sort that out."

Obstruction of justice is a federal crime that bars any attempt to knowingly influence an investigation for improper purposes, including by persuasion, threats and intimidation. Assessing intent is crucial: To prove the crime, prosecutors must show a person's motivation was to "corruptly" persuade someone to influence the course of a judicial proceeding.

Barak Cohen, a former federal prosecutor, said that Thursday's hearing did not provide any "smoking guns" on that score. But Mr. Comey's testimony moved the overall situation "closer to having reasons to investigate for obstruction."

Story continues below advertisement

Meanwhile, Mr. Comey's version of events remains in direct conflict with the President's statements. "It's still 'He said, he said.' I would get ready for an extended investigation," Mr. Cohen observed.

"It's clear that the President had a burr in his saddle about Comey and was preoccupied with how to get this guy on this team," added Sam Buell, a former federal prosecutor and law professor at Duke University. "It suggests a kind of concept of law enforcement where you do things based on relationships and loyalty, not the law."

Prof. Buell, who is an expert on obstruction of justice, said he remains in a "wait-and-see mode" as to whether Mr. Trump's behaviour could be construed as a crime. He emphasized that "obstruction [of justice] doesn't have to succeed in order for it to be illegal."

In his testimony, Mr. Comey also showed a deep desire to protect the FBI from political interference and in so doing, preserve the agency's reputation. Mr. Comey is "worried about returning to an era when the FBI didn't have the public trust," said Timothy Naftali, a presidential historian at New York University.