“I would think that some of these great F.B.I. agents, and the people that work within the F.B.I., I would imagine that they are just furious at what’s happened to the reputation of the F.B.I.,” Mr. Trump said at one campaign rally, in New Hampshire, on Oct. 6.

The next day, on Oct. 7, two top American spy agencies released an intelligence assessment that the Russian government had hacked into the Democratic National Committee with the intent “to interfere with the U.S. election process.” The assessment, by the Office of the Director of National Intelligence and the Homeland Security Department, came after Mr. Trump had complimented President Vladimir V. Putin of Russia and cast doubt on Moscow’s role in the email hacking.

“Maybe there is no hacking,” Mr. Trump said on Oct. 9, in the second presidential debate. “But they always blame Russia. And the reason they blame Russia because they think they’re trying to tarnish me with Russia.”

Once Mr. Trump believed things were going his way, however, he was quick to embrace the intelligence community, which is made up of 17 federal agencies, including the F.B.I. and the C.I.A.

In the final days of the presidential campaign, on Oct. 28, Mr. Comey advised Congress that he was examining new evidence in the closed F.B.I. investigation of Mrs. Clinton’s private email server. Mr. Trump responded by praising Mr. Comey’s “guts” and said the F.B.I. was doing a “good job.” He also condemned Mrs. Clinton for her criticisms of the F.B.I.

“There’s virtually no doubt that F.B.I. Director Comey and the great, great special agents of the F.B.I. will be able to collect more than enough evidence to garner indictments against Hillary Clinton and her inner circle, despite her effort to disparage them and discredit them,” he said at a Nov. 5, 2016, rally in Nevada.

The intelligence assessment about Russian election meddling still irritated him, however — even after he won the presidency. In an unsigned Dec. 10 statement, Mr. Trump’s transition team disparaged the American intelligence community by mocking its role in the lead-up to the Iraq war nearly 15 years earlier. “These are the same people that said Saddam Hussein had weapons of mass destruction,” the statement said. (That 2002 assessment long has been a sore spot for the C.I.A.)