“You don’t understand this part of the world,” the Egyptian leader broke in. “You’re young.”

Mr. Obama, during a tense telephone call the evening of Feb. 1, 2011, had just told Mr. Mubarak that his speech, broadcast to hundreds of thousands of protesters in Tahrir Square in Cairo, had not gone far enough. Mr. Mubarak had to step down, the president said.

Minutes later, a grim Mr. Obama appeared before hastily summoned cameras in the Grand Foyer of the White House. The end of Mr. Mubarak’s 30-year rule, Mr. Obama said, “must begin now.” With those words, Mr. Obama upended three decades of American relations with its most stalwart ally in the Arab world, putting the weight of the United States squarely on the side of the Arab street.

It was a risky move by the American president, flying in the face of advice from elders on his staff at the State Department and at the Pentagon, who had spent decades nursing the autocratic — but staunchly pro-American — Egyptian government.

Nineteen months later, Mr. Obama was at the State Department consoling some of the very officials he had overruled. Anti-American protests broke out in Egypt and Libya. In Libya, they led to the deaths of four Americans, including the United States ambassador to Libya, J. Christopher Stevens. A new Egyptian government run by the Muslim Brotherhood was dragging its feet about condemning attacks on the American Embassy in Cairo.

Television sets in the United States were filled with images of Arabs, angry over an American-made video that ridiculed the Prophet Muhammad, burning American flags and even effigies of Mr. Obama.

Speaking privately to grieving State Department workers, the president tried to make sense of the unfolding events. He talked about how he had been a child abroad, taught to appreciate American diplomats who risked their lives for their country. That work, and the outreach to the Arab world, he said, must continue, even in the face of mob violence that called into question what the United States can accomplish in a turbulent region.

In many ways, Mr. Obama’s remarks at the State Department two weeks ago — and the ones he will make before the General Assembly on Tuesday morning, when he addresses the anti-American protests — reflected hard lessons the president had learned over almost two years of political turmoil in the Arab world: bold words and support for democratic aspirations are not enough to engender good will in this region, especially not when hampered by America’s own national security interests.

In fact, Mr. Obama’s staunch defense of democracy protesters in Egypt last year soon drew him into an upheaval that would test his judgment, his nerve and his diplomatic skill. Even as the uprisings spread to Libya, Yemen, Bahrain and Syria, the president’s sympathy for the protesters infuriated America’s allies in the conservative and oil-rich Gulf states. In mid-March, the Saudis moved decisively to crush the democracy protests in Bahrain, sending a convoy of tanks and heavy artillery across the 16-mile King Fahd Causeway between the two countries.

That blunt show of force confronted Mr. Obama with the limits of his ability, or his willingness, to midwife democratic change. Despite a global outcry over the shooting and tear-gassing of peaceful protesters in Bahrain, the president largely turned a blind eye. His realism and reluctance to be drawn into foreign quagmires has held sway ever since, notably in Syria, where many critics continue to call for a more aggressive American response to the brutality of Bashar al-Assad’s rule.

Mr. Obama’s journey from Cairo to the Causeway took just 44 days. In part, it reflected the different circumstances in the countries where protests broke out, despite their common origins and slogans. But his handling of the uprisings also demonstrates the gap between the two poles of his political persona: his sense of himself as a historic bridge-builder who could redeem America’s image abroad, and his more cautious adherence to long-term American interests in security and cheap oil.

To some, the stark difference between the outcomes in Cairo and Bahrain illustrates something else, too: his impatience with old-fashioned back-room diplomacy, and his corresponding failure to build close personal relationships with foreign leaders that can, especially in the Middle East, help the White House to influence decisions made abroad.

A Focus on Respect

In many ways, Mr. Obama’s decision to throw American support behind change in the Arab world was made well before a Tunisian street vendor set himself on fire and ignited the broadest political challenge to the region in decades.

Mr. Obama, whose campaign for the presidency was in part set in motion by his early opposition to the Iraq war, came into office in January 2009 determined that he would not repeat what he viewed as the mistakes of his predecessor in pushing a “freedom agenda” in Iraq and other parts of the Arab world, according to senior administration officials.

Instead, he focused on mutual respect and understanding. During a speech to the Arab world in 2009 from Cairo, the president did talk about the importance of governments “that reflect the will of the people.” But, he added pointedly, “there is no straight line to realize this promise.”

Photo

IN THE SQUARE In Tahrir Square, the center of Egyptian protests, people watched Mr. Mubarak announce he would not seek office again.Credit
Chris Hondros/Getty Images

Two weeks later, as large street protests broke out in Iran after disputed presidential elections, Mr. Obama followed a low-key script, criticizing violence but saying he did not want to be seen as meddling in Iranian domestic politics.

Months later, administration officials said, Mr. Obama expressed regret about his muted stance on Iran. “There was a feeling of ‘we ain’t gonna be behind the curve on this again,’ ” one senior administration official said. He, like almost two dozen administration officials and Arab and American diplomats interviewed for this article, spoke on the condition of anonymity.

By the time the Tunisian protests broke out in January 2011 — an angry Mr. Obama accused his staff of being caught “flat-footed,” officials said — the president publicly backed the protesters. But the real test of the new muscular posture came 11 days later, when thousands of Egyptians converged on Tahrir Square in Cairo for a “day of rage.”

Mr. Obama felt keenly, one aide said, the need for the United States, and for he himself, to stand as a moral example. “He knows that the protesters want to hear from the American president, but not just any American president,” a senior aide to Mr. Obama said. “They want to hear from this American president.” In other words, they wanted to hear from the first black president of the United States, a symbol of the possibility of change.

If the president felt a kinship with the youthful protesters, he seems to have had little rapport with Egypt’s aging president, or, for that matter, any other Arab leaders. In part, this was a function of time: he was still relatively new to the presidency, and had not built the kind of cozy relationship that the Bush family, for instance, had with the Saudis.

But Mr. Obama has struggled with little success to build better relations with key foreign leaders like Hamid Karzai, the Afghan president, and King Abdullah of Saudi Arabia.

In any case, after an awkward phone call between the American and Egyptian presidents on Jan. 28, Mr. Obama sent a senior diplomat with long experience in Egypt, Frank G. Wisner, to make a personal appeal to the Egyptian leader. But Mr. Mubarak balked. Meanwhile, the rising anger in Cairo’s streets led to a new moment of reckoning for Mr. Obama: Feb. 1.

That afternoon at the White House, top national security officials were meeting in the Situation Room to decide what to do about the deteriorating situation in Egypt. Thirty minutes into it, the door opened and the president walked in, crashing what was supposed to be a principals’ meeting.

Attending were Vice President Joseph R. Biden Jr.; Secretary of State Hillary Rodham Clinton; Defense Secretary Robert M. Gates; the Joint Chiefs of Staff chairman, Adm. Mike Mullen; and the national security adviser, Tom Donilon. Margaret Scobey, the ambassador in Cairo, appeared on the video conference screen.

The question on the table would have been unthinkable just a week before. Should Mr. Obama call for Mr. Mubarak to step down?

An error has occurred. Please try again later.

You are already subscribed to this email.

Midway through the meeting, an aide walked in and handed a note to Mr. Donilon. “Mubarak is on,” he read aloud.

Every screen in the Situation Room was turned to Al Jazeera, and the Egyptian leader appeared, making a much-anticipated address. He said he would not run again, but did not offer to step down. “This is my country,” he said. “I will die on its soil.”

In the Situation Room, there was silence. Then the president spoke. “That’s not going to cut it,” he said.

If this were Hollywood, the story of Barack Obama and the Arab Spring would end there, with the young American president standing with the protesters against the counsel of his own advisers, and hastening the end of the entrenched old guard in Egypt. In the Situation Room, Mr. Gates, Admiral Mullen, Jeffrey D. Feltman, then an assistant secretary of state, and others balked at the inclusion in Mr. Obama’s planned remarks that Mr. Mubarak’s “transition must begin now,” arguing that it was too aggressive.

Mr. Mubarak had steadfastly stood by the United States in the face of opposition from his own public, they said. The president, officials said, countered swiftly: “If ‘now’ is not in my remarks, there’s no point in me going out there and talking.”

John O. Brennan, chief counterterrorism adviser to Mr. Obama, said the president saw early on what others did not: that the Arab Spring movement had legs. “A lot of people were in a state of denial that this had an inevitability to it,” Mr. Brennan said in an interview. “And I think that’s what the president clearly saw, that there was an inevitability to it that would clearly not be turned back, and it would only be delayed by suppression and bloodshed.”

So “now” stayed in Mr. Obama’s statement. Ten days later, Mr. Mubarak was out. Even after the president’s remarks, Mrs. Clinton was still publicly cautioning that removing Mr. Mubarak too hastily could threaten the country’s transition to democracy.

Photo

PROTESTS ARE CRUSHED In February 2011, protesters occupied Pearl Square in Manama, Bahrain, before Saudi Arabia sent in tanks and artillery.Credit
Lynsey Addario for The New York Times

In the end, many of the advisers who initially opposed Mr. Obama’s stance now give him credit for prescience. But there were consequences, and they were soon making themselves felt.

Angry Reactions

On Feb. 14, in the tiny island monarchy of Bahrain, Internet calls for a “day of rage” led to street rallies and bloody clashes with the police. The next day at a news conference in Washington, Mr. Obama seemed to suggest that this revolt was much like the others. His message to Arab allies, he said, was “if you are governing these countries, you’ve got to get out ahead of change.”

But in the following weeks, Mr. Obama fell silent. Away from the public eye, he was coming under assault from leaders in Saudi Arabia, the United Arab Emirates, even Israel. Angry at the treatment of Mr. Mubarak, which officials from the Gulf states feared could forecast their own abandonment, Saudi Arabia and the United Arab Emirates drew a line in the sand. Some American and Arab diplomats say that response could have been avoided if Mr. Obama had worked quietly to ease Mr. Mubarak out, rather than going public.

On March 14, White House officials awoke to a nasty surprise: the Saudis had led a military incursion into Bahrain, followed by a crackdown in which the security forces cleared Pearl Square in the capital, Manama, by force. The moves were widely condemned, but Mr. Obama and Mrs. Clinton offered only veiled criticisms, calling for “calm and restraint on all sides” and “political dialogue.”

The reasons for Mr. Obama’s reticence were clear: Bahrain sits just off the Saudi coast, and the Saudis were never going to allow a sudden flowering of democracy next door, especially in light of the island’s sectarian makeup. Bahrain’s people are mostly Shiite, and they have long been seen as a cat’s paw for Iranian influence by the Sunni rulers of Saudi Arabia and Bahrain. In addition, the United States maintains a naval base in Bahrain that is seen as a bulwark against Iran, crucial for maintaining the flow of oil from the region.

“We realized that the possibility of anything happening in Saudi Arabia was one that couldn’t become a reality,” said William M. Daley, President Obama’s chief of staff at the time. “For the global economy, this couldn’t happen. Yes, it was treated differently from Egypt. It was a different situation.”

Some analysts credit Mr. Obama for recognizing early on that strategic priorities trumped whatever sympathy he had for the protesters. Others say the administration could have more effectively mediated between the Bahraini government and the largely Shiite protesters, and thereby avoided what has become a sectarian standoff in one of the world’s most volatile places.

If Mr. Obama had cultivated closer ties to the Saudis, he might have bought time for negotiations between the Bahraini authorities and the chief Shiite opposition party, Al Wefaq, according to one American diplomat who was there at the time. Instead, the Saudis gave virtually no warning when their forces rolled across the causeway linking Saudi Arabia and Bahrain, and the ensuing crackdown destroyed all hopes for a peaceful resolution.

The lingering resentment over Mr. Mubarak’s ouster had another apparent consequence. Mrs. Clinton’s criticism of the military intervention in a Paris television interview angered officials of the United Arab Emirates, whose military was also involved in the Bahrain operation and who shared the Saudis’ concern about the Mubarak episode.

The Emiratis promptly threatened to withdraw from the coalition then being assembled to support a NATO-led strike against Col. Muammar el-Qaddafi, the Libyan leader. The Emiratis knew they were needed to give the coalition legitimacy. They quickly named their price for staying on board, according to Arab and Western diplomats familiar with the episode: Mrs. Clinton must issue a statement that would pull back from any criticism of the Bahrain operation.

The statement, hastily drafted and vetted by Emirati and American officials, appeared soon afterward, in the guise of a communiqué on Libya.

The tensions between Mr. Obama and the Gulf states, both American and Arab diplomats say, derive from an Obama character trait: he has not built many personal relationships with foreign leaders. “He’s not good with personal relationships; that’s not what interests him,” said one United States diplomat. “But in the Middle East, those relationships are essential. The lack of them deprives D.C. of the ability to influence leadership decisions.”

Arab officials echo that sentiment, describing Mr. Obama as a cool, cerebral man who discounts the importance of personal chemistry in politics. “You can’t fix these problems by remote control,” said one Arab diplomat with long experience in Washington. “He doesn’t have friends who are world leaders. He doesn’t believe in patting anybody on the back, nicknames.

“You can’t accomplish what you want to accomplish” with such an impersonal style, the diplomat said.

Mr. Obama’s advisers argue that when he does reach out, he is more effective — as in a phone call last week to Mohamed Morsi, the new president of Egypt. After Mr. Morsi’s initial tepid response to the attacks on the embassy in Cairo, a fed-up Mr. Obama demanded a show of support. Within an hour, he had it.

“Were he to be calling all the time, it would run counter to our assertion that we won’t dictate the outcome of every decision in every country,” said Benjamin J. Rhodes, a top national security aide. Limiting his outreach, Mr. Rhodes said, “heightens the impact of presidential engagement” when Mr. Obama does get on the phone.

Still, there remains concern in the administration that at any moment, events could spiral out of control, leaving the president and his advisers questioning their belief that their early support for the Arab Spring would deflect longstanding public anger toward the United States.

For instance, Mr. Feltman, the former assistant secretary of state, said, “the event I find politically most disturbing is the attack on Embassy Tunis.” Angry protesters breached the grounds of the American diplomatic compound there last week — in a country previously known for its moderation and secularism — despite Mr. Obama’s early support for the democracy movement there. “That really shakes me out of complacency about what I thought I knew.”

A version of this article appears in print on September 25, 2012, on Page A1 of the New York edition with the headline: In Arab Spring, Obama Finds A Sharp Test. Order Reprints|Today's Paper|Subscribe