In the days after President Trump fired James Comey as FBI director, law enforcement officials became so concerned by the president's behaviour that they began investigating whether he had been working on behalf of Russia against American interests, according to former law enforcement officials and others familiar with the investigation.
Counter-intelligence investigators had to consider whether the president's own actions constituted a possible threat to national security.
Agents also sought to determine whether Trump was knowingly working for Russia or had unwittingly fallen under Moscow's influence.
The probe the FBI opened into Trump also had a criminal aspect, which has long been publicly known: whether his firing of Comey constituted obstruction of justice.
Agents and senior FBI officials had grown suspicious of Trump's ties to Russia during the 2016 campaign but held off on opening an investigation into him, the people said, in part because they were uncertain how to proceed with an inquiry of such sensitivity and magnitude.
But the president's activities before and after Comey's firing in May 2017, particularly two instances in which Trump tied the Comey dismissal to the Russia probe, helped prompt the counterintelligence aspect of the inquiry, the people said.
Special counsel Robert Mueller took over the inquiry into Trump when he was appointed, days after FBI officials opened it.
That inquiry is part of Mueller's broader examination of how Russian operatives interfered in the 2016 election and whether any Trump associates conspired with them.
It is unclear whether Mueller is still pursuing the counterintelligence matter.
The criminal and counter-intelligence elements were coupled together into one investigation, former law enforcement officials said in interviews in recent weeks, because if Trump had ousted the head of the FBI to impede or even end the Russia investigation, that was both a possible crime and a national security concern.
Trump blasted the FBI on Saturday, insisting it acted "for no reason & with no proof".
"Wow, just learned in the Failing NYT that the corrupt former leaders of the FBI, almost all fired or forced to leave the agency for some very bad reasons, opened up an investigation on me, for no reason & with no proof, after I fired Lyin' James Comey, a total sleaze!" the US President tweeted.