WASHINGTON — In the days after President Trump fired James B. Comey as F.B.I. director, law enforcement officials became so concerned by the president’s behavior 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.The inquiry carried explosive implications. Counterintelligence investigators had to consider whether the president’s own actions constituted a possible threat to national security. Agents also sought to determine whether Mr. Trump was knowingly working for Russia or had unwittingly fallen under Moscow’s influence.The investigation the F.B.I. opened into Mr. Trump also had a criminal aspect, which has long been publicly known: whether his firing of Mr. Comey constituted obstruction of justice.Agents and senior F.B.I. officials had grown suspicious of Mr. 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 Mr. Comey’s firing in May 2017, particularly two instances in which Mr. Trump tied the Comey dismissal to the Russia investigation, helped prompt the counterintelligence aspect of the inquiry, the people said.