CAIRO -- As President Mohamed Morsi huddled in his guard's quarters during his last hours as Egypt's first elected leader, he received a call from an Arab foreign minister with a final offer to end a standoff with the country's top generals, senior advisers with the president said.
The foreign minister said he was acting as an emissary of Washington, the advisers said, and he asked if Mr. Morsi would accept the appointment of a new prime minister and cabinet, one that would take over all legislative powers and replace his chosen provincial governors.
The aides said they already knew what Mr. Morsi's answer would be. He had responded to a similar proposal already by pointing at his neck. "This before that," he had told his aides, repeating a vow to die before accepting what he considered a de facto coup and thus a crippling blow to Egyptian democracy.
His top foreign policy adviser, Essam el-Haddad, then left the room to call the United States ambassador, Anne W. Patterson, to say that Mr. Morsi refused. When he returned, he said he had spoken to Susan E. Rice, the national security adviser, and that the military takeover was about to begin, senior aides said.
"Mother just told us that we will stop playing in one hour," an aide texted an associate, playing on a sarcastic Egyptian expression for the country's Western patron, "Mother America."
The White House had no immediate comment on American involvement in the final hours of the Morsi government.
The abrupt end of Egypt's first Islamist government was the culmination of months of escalating tensions and ultimately futile American efforts to broker a solution that would keep Mr. Morsi in his elected office, at least in name, if not in power. A new alliance of youthful activists and the Mubarak-era elite was driving street protests. The demonstrations had raised pressure on the Muslim Brotherhood, the once-outlawed Islamist group that had finally come to power with Mr. Morsi after the ouster of the former president, Hosni Mubarak. And the alliance between Mr. Morsi and the nation's top generals was gradually unraveling.
In the end, senior Brotherhood officials said, Mr. Morsi's adamant response to that last offer -- a combination of idealism and stubbornness -- epitomized his rule. It may also have doomed his presidency.
As long ago as the fall, he had spoken fatalistically of the possibility of his own ouster, his senior advisers said. "Do you think this is the peak?" he asked a visibly anxious aide during his first major political crisis. "No," Mr. Morsi said with resignation, "The peak will be when you see my blood flowing on the floor."
This was just after what his advisers and Muslim Brotherhood leaders now acknowledge was the defining blunder of his one-year presidency. Battling Mubarak-appointed judges who had dissolved the Islamist-led Parliament, Mr. Morsi had issued a presidential declaration in November that set his authority above the courts until a constitutional convention could finish its work.
Tens of thousands of protesters denounced his tactic as authoritarian, setting off the first major street fighting between his supporters and opponents. Even some of his allies in the Muslim Brotherhood were angered, the group's leaders and presidential advisers said. They complained that he had not consulted them, but still expected them to defend him in the streets.
"If I were not in my place, I would think he wants to be a dictator," one Muslim Brotherhood leader said when he heard the news on television, a colleague recounted on condition of anonymity.
Mr. Morsi, though, feared he would appear weak if he backed down, his advisers said. "The president is headstrong," lamented another Brotherhood leader.
Mr. Morsi never believed the generals would turn on him as long as he respected their autonomy and privileges, his advisers said. He had been the Muslim Brotherhood's designated envoy for talks with the ruling military council after the ouster of Mr. Mubarak. And his counterpart on the council was Gen. Abdul-Fattah el-Sisi.
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 president take full control of his government. The relationship with the military was Mr. Morsi's "personal file," one adviser said.
But during the fall protests charging the Brotherhood with monopolizing power, General Sisi first signaled that his departure from politics might not be so permanent. Without consulting Mr. Morsi, General Sisi publicly invited all the country's political factions -- from social democrats to ultraconservative sheiks -- to a meeting to try to hammer out a compromise on a more inclusive government. Mr. Morsi quashed the idea, advisers said.
General Sisi said publicly last week he continued after that to try to broker some compromise with the opposition and to ease the paralysis of Egyptian politics. It was at that point, Mr. Morsi's advisers say, that they first suspected General Sisi of intrigue.
Mr. Morsi, they say, often pressed General Sisi to stop the threatening or disparaging statements toward the president from unnamed military officials in the news media. General Sisi merely said "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, his advisers said. Mr. Morsi was the last one in the inner circle to acknowledge that General Sisi was ousting them. The United States officials repeatedly urged Mr. Morsi to compromise with the opposition and include it in government. In December, President Obama met with Mr. Haddad, Mr. Morsi's foreign policy adviser, in the Oval Office to deliver the message, Mr. Morsi's advisers said. At one point, the advisers said, Mr. Obama offered to intervene with the opposition leaders, either Mohamed ElBaradei, the former United Nations diplomat, or Amr Moussa, a former foreign minister under Mr. Mubarak. But Mr. Morsi declined.
Embassy officials tried to act as intermediaries, Morsi advisers said. But this year, Ms. Patterson pointedly told Mr. Morsi's aides that some in Washington were running out of patience with her defense of Egypt's new Islamist leaders, his advisers said.
By June, the economy was sputtering, with gas shortages and blackouts. Young organizers tapped into the growing discontent with a petition drive calling for Mr. Morsi's removal, and it was set to culminate in a demonstration on the anniversary of his inauguration, June 30.
The first alarms went off in Mr. Morsi's inner circle on June 21, when General Sisi issued a public statement warning that the growing "split in society" between Mr. Morsi's supporters and opponents compelled the military "to intervene."
Mr. Morsi was given no warning, his advisers said. But when Mr. Morsi called the general, General Sisi told the president that "it was to satisfy some of his men" and that "it was nothing more than an attempt to absorb their anger," one of Mr. Morsi's advisers said. "So even after that first statement, the president didn't think a coup was imminent."
The day before the protests, General Sisi called Mr. Morsi to press him for a package of concessions, including a new cabinet. But Mr. Morsi refused, saying he needed to consult first with his Islamist coalition.
When the protests came last Sunday, demonstrators were energized by the general's warning about an intervention. Millions poured into the streets.
"You would think he would have to do something," a senior Brotherhood official told a reporter that night, on the condition of anonymity. "The president is stubborn."
Inside Mr. Morsi's office. Mr. Morsi's team checked the official crowd count, sent its own observers, monitored the gathering on Google Earth, and even compared the numbers of mobile phone signals in various public squares, one adviser said, and mistakenly concluded that the pro-Morsi rally in Cairo outnumbered the protests against him.
"We felt a sense of relief," the adviser said.
The next day, on Monday, General Sisi gave political leaders a 48-hour ultimatum to reach a compromise. A shaken Morsi adviser, speaking on the condition of anonymity, said at the time the president's team considered it "a military coup."
Mr. Morsi's advisers had meetings with Ms. Patterson and her deputy as well as a phone call with Ms. Rice, the national security adviser. Mr. Morsi's advisers argued that ousting the president would be "a long term disaster" for Egypt and the Arab world because people would "lose faith in democracy." They said it would set off an explosion in the streets that they could not control.
And they argued that the United States was implicated: "Nobody who knows Egypt is going to believe a coup could go forward without a green light from the Americans."
The advisers say the Americans encouraged them to see hope of a compromise; one adviser told a reporter that night that their fears had receded.
At a meeting with General Sisi at 2 p.m. the next day, Mr. Morsi's advisers said that they had their coalition's blessing to accept the earlier concessions the general had suggested before the protest.
But when the general returned to the Republican Guard building at 6 p.m., he said "the opposition" had balked, the advisers said.
Mr. Morsi's team did not know who the general actually consulted and the young protest leaders and some other opposition leaders said they did not know either. But that night Mr. Morsi delivered a fiery address denouncing his opponents as traitorous conspirators.
General Sisi later publicly cited the speech as a turning point in his decision to act.
On Wednesday, the generals convened a four-hour meeting at military headquarters with protest and opposition party leaders. The head of Mr. Morsi's Islamist party, now jailed, was invited but did not attend.
"General Sisi was a very good listener," said Mohamed Abdel Aziz, one of the young protest organizers who attended.
In Washington, officials stepped back and said little.
Mr. Morsi had been working out of his guards' house for his own security during the protests. As he waited to be arrested, he told stories about the politicians of his youth. "He was as relaxed as I've ever seen him," one adviser said.
As the last aides to leave walked out, one heard a general tell his guards: "Lock the gates."
This article originally appeared in The New York Times.