Earlier in his career, James Comey earned a reputation for standing up to the White House. Now he appears to be on a collision course with the new President.

On Monday, Mr. Comey, the director of the U.S. Federal Bureau of Investigation, testified before federal lawmakers that his agency is conducting a counterintelligence investigation of contacts between Russian officials and associates of President Donald Trump. Mr. Comey also said there was no evidence to support Mr. Trump's claim that former president Barack Obama illegally wiretapped Trump Tower.

Mr. Comey is emerging as the most consequential FBI director in decades. Indeed, Monday's hearing marked the second time in the past six months that Mr. Comey has sent shockwaves through U.S. politics.

Story continues below advertisement

In October, 11 days before the presidential election, he told lawmakers about a previously unknown cache of messages found on a laptop belonging to an aide to Democratic candidate Hillary Clinton. The revelation reignited the controversy surrounding Ms. Clinton's use of a private e-mail server. Then, two days before the vote, Mr. Comey said the new e-mails did not change the FBI's earlier decision not to recommend any charges in the probe.

Sarah Kendzior: At long last, a forum where Trump cannot escape the truth

To his defenders, Mr. Comey is a man of principle who is navigating extraordinary and hazardous political terrain. His critics agree on Mr. Comey's integrity but argue he made errors in judgment in his handling of Ms. Clinton's case, with lasting consequences for future investigations.

Now Mr. Comey will play a key role in the future course of Mr. Trump's presidency. Mr. Comey "is conducting what may be the most consequential counterintelligence investigation since the Soviets stole the secrets of the atom bomb," said Tim Weiner, the author of a book on the history of the FBI.

Story continues below advertisement

It is a role that Mr. Comey has prepared for throughout his career. A registered Republican for much of his life, Mr. Comey, 56, studied religion in university before training as a lawyer. He gained a reputation as a tenacious prosecutor who inspired fervent loyalty in subordinates. Mr. Comey is also known for his lively sense of humour and elevated stature (he stands 6 feet, 8 inches tall).

In 2004, Mr. Comey was a senior official at the Justice Department under George W. Bush. When John Ashcroft, the U.S. attorney-general, fell ill and was hospitalized, Mr. Comey briefly assumed his duties. In a legendary confrontation, Mr. Comey thwarted an effort by a senior aide to Mr. Bush to pressure the ailing Mr. Ashcroft to reauthorize a warrantless wiretapping program.

Soon after, Mr. Comey and then-FBI director Robert Mueller informed Mr. Bush that they would both resign if the President continued the program in its existing form, which Mr. Comey did not believe was legal. Faced with a revolt at the top levels of the Justice Department, Mr. Bush backed down.

Mr. Comey's reputation for probity and independence gained the attention of Mr. Obama, who appointed him FBI director in 2013. David Kelley, a long-time friend and former colleague of Mr. Comey, described him as "a moral compass" guided solely by doing what is right. "When that's your operating principle, there aren't a lot of tough decisions," said Mr. Kelley, who was formerly the top federal prosecutor in Manhattan.

Story continues below advertisement

Assertions that Mr. Comey acted out of partisan motivations in his handling of the investigation into Ms. Clinton's e-mail server are "just silly," said Mr. Kelley. "Another way you could look at it is, he basically has thrown himself in front of the bus in order to preserve the bureau."

In nearly all cases, the FBI and federal prosecutors refrain from discussing any investigation unless and until charges are filed. But Mr. Comey has deviated from that stance, creating an expectation that he will provide further updates on the investigation into the Trump campaign.

"Presumably he would be under pressure to confirm when it's over and done with, just like Hillary," said David Rivkin, a former White House counsel and Justice Department official. "We're in uncharted waters."

The FBI has a history of making things uncomfortable or worse for presidents, noted Mr. Weiner. During Richard Nixon's presidency, the confidential source for key information about the Watergate scandal was a senior FBI official. Under Ronald Reagan, the bureau investigated senior administration officials for their involvement in the Iran-Contra Affair and 14 of them faced criminal charges. FBI agents also worked for the special prosecutor investigating the Monica Lewinsky scandal that led to impeachment proceedings against Bill Clinton.

Story continues below advertisement

The ongoing investigation will make the relationship between Mr. Comey and Mr. Trump awkward to say the least. In a normal situation, the FBI director has regular meetings with the President and serves as a close adviser on matters of national security.

"I don't have any questions about Comey's independence, but it's very tough to conduct an investigation into your boss," said Matthew Miller, a former spokesman for the Justice Department. For that reason, Mr. Miller believes it would be better to appoint a special prosecutor to oversee the probe.

Mr. Comey's term at the helm of the FBI doesn't expire until 2023. While Mr. Trump can remove Mr. Comey from his post, such a move would be exceedingly controversial. In the meantime, Mr. Comey is unlikely to back away from seeing the probe through to its conclusion. A good prosecutor pursues cases "without fear or favour," said Mr. Kelley, who has known Mr. Comey for decades. "If anybody's going to do that, he's going to do that."