The Egyptian president startled the Obama administration and many of his aides with an address in which he appeared determined to cling to office. The speech surprised and angered the White House, enraged Cairo's legions of protesters and pushed the country closer to chaos, current and former US government officials said in interviews recounting the events of the past 48 hours.

In the end, Mubarak's efforts only ensured a hasty and ignominious departure, the officials said. Within hours of the speech, Egyptian army officials confronted the discredited president with an ultimatum: Step down voluntarily or be forced out.

Mubarak's defiant speech - described by some US officials as bordering on delusional - was a final, wild plot twist in a saga that had played out in Egypt and Washington over the past 18 days. The likelihood of Mubarak's departure alternately rose and dipped as US military officers and diplomats quietly worked with their Egyptian counterparts in a search for peaceful resolution to the country's worst unrest in six decades.

cnxps.cmd.push(function () { cnxps({ playerId: '36af7c51-0caf-4741-9824-2c941fc6c17b' }).render('4c4d856e0e6f4e3d808bbc1715e132f6'); });

By midweek, confronted with growing throngs in Cairo, labor strikes and deteriorating economic conditions, top military and civilian leaders reached an apparent agreement with Mubarak on some form of power transfer. The details of the plan - and how it unraveled Thursday - were described in interviews with six former and current US government officials who were knowledgeable about the details. Most of the sources insisted on anonymity in agreeing to talk about the administration's internal policy discussions and diplomatic exchanges with Egyptian officials.

Click here for full Jpost coverage of unrest in Egypt

Communication between top US and Egyptian officials had become increasingly sporadic early this week as Mubarak deputies complained publicly about US interference in Cairo's affairs. But then US intelligence and military officials began to learn details of the the plan by Egyptian military leaders - something between a negotiated exit and a soft coup d'etat - to relieve Mubarak of most, if not all, of his powers.

The plan went into effect Thursday with announcements in Cairo to pro-democracy demonstrators that their key demands were about to be met. A rare meeting was convened of Egypt's Supreme Council of the Armed Forces, and afterward a military spokesman released a communique that seemed to assert the army's control over the government. The statement stressed "the responsibility of the armed forces and its commitment to protect the people and its keenness to protect the nation."

The statement prompted cheers among the hundreds of thousands of demonstrators who had gathered in Cairo's Tahrir Square anticipating an announcement of Mubarak's departure.

Hours later in Washington, CIA Director Leon Panetta made a scheduled appearance before the House Intelligence Committee. Asked about Egypt, he cited reports suggesting a "strong likelihood that Mubarak may step down this evening." The CIA retreated from the assertion, saying the director was referring to news reports, but the agency's classified cables continued to point to a likely transfer of power in Egypt that day, according to two US officials familiar with the intelligence.

US President Barack Obama was en route to Marquette, Mich., for an event on wireless technology. Just before 2 p.m. Washington time, he took to the stage at Northern Michigan University to signal his approval for a transfer of power in Egypt that appeared to be only minutes away. "We are witnessing history unfold," an ebullient Obama said.

His words hinting of historic changes under way in Egypt were meant to express optimism without forecasting when Mubarak might surrender his powers, an administration official said. But the speech added to the growing anticipation about a speech by the Egyptian president set to take place two hours later.

A solemn-looking Mubarak appeared on Egypt's state television just as Obama was returning to Washington. The US president and his aides watched with increasing dismay as Mubarak criticized Western interference and ticked off a list of promises for the coming months. Although he referred vaguely to a decision to transfer "some of the power" to his newly appointed vice president, Omar Suleiman, his tone was defiant and he offered no hint of stepping down.

US officials and Middle East experts who analyzed the speech said it was a case of extraordinary miscalculation on Mubarak's part. "It was a public relations disaster," said Daniel Kurtzer, a former US ambassador to Egypt. The speech provoked roars of outrage from Tahrir Square as thousands of demonstrators began to march on the presidential palace and state TV headquarters, many of them shouting, "Leave, leave."

"Mubarak went off script," said said Scott Carpenter, a Middle East expert with the Washington Institute for Near East Policy. "But it wasn't what he said so much as it was the way he said it. He essentially agreed to say everything the army wanted him to say, but he couldn't say it the way people expected him to."

After landing in Washington, Obama assembled his national security team in the Oval Office to discuss the response. He sat down afterward to pen a first draft of his public response, choosing language that more clearly than ever put the White House on the side of the demonstrators. The final version began with this sentence: "The Egyptian people have been told that there was a transition of authority, but it is not yet clear that this transition is immediate, meaningful or sufficient."

"It unmistakably aligned us with the aspirations of the people in Tahrir Square," said a senior administration official involved in the Oval Office meeting.

It was a crucial shift for a White House that had been the scene of sometimes heated exchanges between aides who pressed for a strong message of support for democratic change in Egypt and others who worried that doing so could disrupt the traditional government-to-government relationship with a key ally.

There was a discernible change in Cairo, as well. Within hours of Mubarak's speech, "support for Mubarak from the8 military dropped precipitously," said a US government official who closely tracked the events.

"The military had been willing - with the right tone in the speech - to wait and see how it played out," the official said. "They didn't like what they saw."

Even Suleiman, Mubarak's longtime intelligence chief, joined ranks with military leaders late Thursday. "He had been trying to walk a fine line between retaining support for Mubarak while trying to infuse common sense into the equation," the US official said. "By the end of the day, it was clear the situation was no longer tenable."

Mubarak was told Friday that he must step down, and within hours, he was on his way to the Red Sea resort of Sharm e-Sheikh. It was Suleiman who announced the change in leadership. At 11 a.m. Cairo time, the vice president stood before a television camera to formally declare the end of three decades of Mubarak rule.

"[Egyptian] President Hosni Mubarak has decided to step down from the office of president of the republic and has charged the high council of the armed forces to administer the affairs of the country," Suleiman said. "May God help everybody."