Civilians in government were skeptical, too. Secretary of State John Kerry had grown close to many of the most fiercely anti-Islamist Persian Gulf royals during his decades in the Senate, even sometimes yachting with them. He had always distrusted the Brotherhood, he told me years later. When he visited Cairo for the first time as secretary of state in March 2013, he took an immediate dislike to Mr. Morsi.

“He is the dumbest cluck I ever met,” Mr. Kerry told his chief of staff as they left the presidential palace. “This isn’t going to work. These guys are wacko.”

Mr. Kerry got along better in his one-on-one meeting with Gen. Abdel Fattah el-Sisi. A former military intelligence chief, General Sisi had vaulted himself into the job of defense minister in a shake-up just a few months before.

“I will not let my country go down the drain,” General Sisi told Mr. Kerry, as he later recalled to me. He knew then that “Morsi was cooked.” General Sisi was prepared to intervene. Mr. Kerry felt partly relieved, he told me.

“It was reassuring that Egypt would not fall into a civil war or a complete massacre of the public or an implosion,” Mr. Kerry said, although he added, “I did not sit back and think, ‘Great, our problems are going to be solved.’”

Senior American diplomats in Cairo had told me that March that a military intervention was “extraordinarily unlikely.” But by the next month, Ambassador Anne Patterson was picking up other signals from the top generals. In an encrypted email, she warned at least some in the White House that “if not imminent, a coup was a high likelihood within a few months,” one official told me. She predicted that any military intervention would surely be brutal.

The White House was sending Secretary of Defense Chuck Hagel talking points intended to warn General Sisi that Washington would punish a coup. Among other things, United States law mandated a cutoff of aid to any military that overturned an elected leader.