And yet the announcement on Friday still hit the White House like a thunderclap. The president’s legal team had no advance warning. His chief of staff, John F. Kelly, learned about it from television. He called Mr. Trump, who was still in the residence part of the White House, to let him know he would be hearing about a Flynn plea deal soon. The president’s reaction, according to one adviser, was that Mr. Flynn “is in a lot of trouble.”

Whether that fear turned into something more immediate about himself or his family, Mr. Trump did not vocalize it, the adviser said. His staff urged him to stay off Twitter, and for the most part, he complied. The president had a cordial, if at times awkward, lunch with Secretary of State Rex W. Tillerson, and then used Twitter to deny any plans to fire him. In the afternoon, Mr. Trump stopped by a White House Christmas party for reporters but stayed less than five minutes.

The president’s optimistic outlook last weekend was fueled by his White House lawyer, Ty Cobb, who has consistently assured him that the investigation by Mr. Mueller would most likely conclude by the end of the year. Mr. Cobb has successfully persuaded Mr. Trump for the most part to curb his combative instincts and work in the parameters of Mr. Mueller’s investigation, turning over requested documents and avoiding incendiary attacks on the prosecutor.

But Mr. Trump has been slipping free of Mr. Kelly’s restrictions for several weeks, speaking with old friends by telephone during his Mar-a-Lago trip and becoming incensed all over again about the Russia inquiry. Friends said he was particularly excitable in his phone calls in the days leading up to Mr. Flynn’s guilty plea, a mood that seemed reflected by a week of lashing out on Twitter at various targets other than the investigators.

He has been so fitful that at one point during his stay in Florida, he told some club members that he was not fretting about whether Senate Republicans would pass his tax proposal because he had “a plan.” If the Senate failed to approve his tax cuts, Mr. Trump told them, he would refuse to sign a new short-term spending bill financing the government, forcing a partial shutdown.

Aides insist that Mr. Trump is not consumed with the Russia inquiry more than he has been at other times. Yet he has been leaning on Mr. Cobb, constantly summoning him to the residence and dialing another lawyer on his team, Jay Sekulow, for consultations, people briefed on the discussions said.

The White House made a point of playing down any appearance of concern on Friday. A statement issued by Mr. Cobb diminished Mr. Flynn’s importance by noting that he served as national security adviser for only 25 days before being fired for misleading Vice President Mike Pence and others about the details of his conversation with a Russian ambassador.