Mr. Comey was addressing a group of F.B.I. employees in Los Angeles when a television in the background flashed the news that he had been fired.

In response, Mr. Comey laughed, saying he thought it was a fairly funny prank.

Then his staff started scurrying around in the background and told Mr. Comey that he should step into a nearby office.

Mr. Comey stopped addressing the group. He proceeded to shake hands with the employees he had been speaking to. Then he stepped into a side office, where he confirmed that he had been fired. At that point, he had not heard from the White House.

Shortly thereafter, a letter from Mr. Trump was delivered to the F.B.I.’s headquarters, just seven blocks from the White House.

Mr. Comey’s day had begun in Florida, where he spoke to a group of police officers. He then flew to Los Angeles, where he was also scheduled to speak at a diversity meeting.