The Brotherhood was naturally suspicious of the military, its historical opponent, but General Sisi cultivated Mr. Morsi and other leaders, one of them said, including going out of his way to show that he was a pious Muslim. “That is how the relationship between the two of them started,” said a senior Brotherhood official close to Mr. Morsi. “He trusted him.”

The two grew so close that Mr. Morsi caught his advisers by surprise when he promoted General Sisi to defense minister last summer as part of a deal that persuaded the military for the first time to let the elected president take full control of his government. Mr. Morsi kept relations with the military as his “personal file,” and worked out the deal without consulting his aides, one adviser said.

But the generals’ exit, however, only redoubled the criticism from Mr. Morsi’s opponents that the Islamists were monopolizing power.

Mr. Morsi failed to broaden his appeal among the sectarian opposition, and amid complaints that he and the Brotherhood were monopolizing power. And when the protests took off last fall, General Sisi signaled that his departure from politics might not be so permanent. Without consulting Mr. Morsi, the general publicly invited all the country’s fractious political factions — from social democrats to ultraconservative sheiks — to a meeting to try to come to a compromise on a more inclusive government. Mr. Morsi quashed the idea, advisers said, to avoid drawing the generals back into politics.

General Sisi said publicly last week that he continued to try to broker some compromise with the opposition and to ease the political polarization. It was at that point, Mr. Morsi’s advisers said, that they first suspected General Sisi of intrigue.

Mr. Morsi, they said, often pressed the general to stop unnamed military officials from making threatening or disparaging statements toward the president in the news media. General Sisi merely said that “newspapers and media exaggerate,” and that he was “trying to control the tensions toward the president inside the military,” one adviser said.

Yet Mr. Morsi insisted to his aides that he remained fully confident that General Sisi would not interfere, almost until the end of his presidency. He was the last one in the inner circle to acknowledge last week that General Sisi was ousting them.