President Obama had just arrived home, walking across Lafayette Square after attending Sunday services with his family at St. John’s Church. In the West Wing, Obama ducked into the spacious office of his chief of staff, where he found his negotiating team huddled with two leading Republicans and a passel of aides.

To the outside world, it looked like a do-nothing summer Sunday, a disturbingly quiet reminder of government dysfunction. The prevailing theme on the weekly political talk shows was things falling apart. In two weeks, the government would be unable to pay its bills. Where were the administration and congressional leaders who might work out a compromise to avert the looming disaster? No meetings were taking place at the White House that day, one network host said.

The reality was quite different. Around 11 a.m. July 17, John A. Boehner, the House speaker, and Eric Cantor, the majority leader, had slipped through a side entrance, out of view from the bank of television cameras stationed near the front gate off Pennsylvania Avenue. The on-and-off secret negotiations were on again. They had resumed with a Friday meeting at the Capitol. And they seemed to be going so well by the time Obama returned from church that he invited Boehner and Cantor into the Oval Office to talk, just the three of them.

The sermon the president had heard that morning was a stirring Old Testament account of Jacob dreaming of a ladder that stretched to heaven. Sometimes, the pastor had said, “the best adventures occur when we venture into unmarked terrain.” Obama was in a similar frame of mind. Against the vehement advice of many Democrats, including some of his own advisers, Obama was pursuing a compromise with his ideological opponents, a “grand bargain” that would move into unmarked territory, beyond partisan divides, pushing both parties to places they did not want to go. Now might be the moment.

Months later, that moment and the tense, ultimately unsuccessful ones that followed have become a critical issue in Obama’s reelection campaign as the president and his Republican critics lay out competing narratives about his stewardship of the economy and the United States’ fiscal health.

Republicans say those days offer clear evidence that the president is fiscally reckless and determined to tax his way out of the nation’s mounting deficit and debt problems. A Washington Post-ABC News poll this month illustrates Obama’s lingering vulnerability: Only about a third of Americans approve of his handling of the deficit.

From the White House point of view, those few days show a politically selfless president willing to rise above the partisan fray and make difficult choices for the good of the country — if only obstinate Republicans would meet him halfway.

On that Sunday in July, Boehner, the old-school pol from Ohio, seemed willing to hash it out. He had met in private with the president and his aides many times. Their sessions were so sensitive — especially for the speaker, who was dealing with a House teeming with tea party rebels — that Obama’s aides were under strict orders to “protect Boehner” and not talk about his private entreaties. Obama liked Boehner; they got along well during the private sessions and a round of golf. But there was doubt in the White House as to whether the speaker could bring his party along. He “probably could not deliver a pizza,” was one administration aide’s skeptical assessment.

Cantor, a Virginian, was more closely aligned with the tea party wing. The fact that he was there, and had been involved since Friday, however reluctantly, was taken by the White House as an encouraging sign.

The conversation during that brief gathering inside the Oval Office did nothing to dampen the optimism. When the trio emerged and returned to the roomful of aides, Obama appeared upbeat.

“I want a deal,” he said.

The aides put down their muffins and BlackBerrys and snapped to attention.

Secrecy would be essential as the details came together, the president told everyone. He spoke openly with Boehner about how the two sides might sell the emerging plan to their respective parties, an imposing task from either end.

“How soon can we get this drafted?” the president asked, according to notes taken during the meeting by a top Republican staff member. When Obama left, the negotiations rushed forward, staffers on both sides now energized by the prospect of a deal.

What happened? Obama and his advisers have cast the collapse of the talks as a Republican failure. Boehner, unable to deliver, stepped away from the deal, simple as that.

But interviews with most of the central players in those talks — some of whom were granted anonymity to speak about the secret negotiations — as well as a review of meeting notes, e-mails and the negotiating proposals that changed hands, offer a more complicated picture of the collapse. Obama, nervous about how to defend the emerging agreement to his own Democratic base, upped the ante in a way that made it more difficult for Boehner — already facing long odds — to sell it to his party. Eventually, the president tried to put the original framework back in play, but by then it was too late. The moment of making history had passed.

The actions of Obama and his staff during that period in the summer reflect the grand ambitions and the shortcomings of the president’s first term.

A president who promised to bring the country together, who confidently presented himself as the transformational figure able to make that happen, now had his chance. But, like earlier policy battles, the debt ceiling negotiations revealed a divided figure, a man who remained aloof from a Congress where he once served and that he now needed. He was caught between his own aspirations for historical significance and his inherent political caution. And he was unable to bridge a political divide that had only grown wider since he took office with a promise to change the ways of Washington, underscoring the gulf between the way he campaigned and the way he had governed.

In the end, that brief effort, described by White House officials as the most intense and consequential of Obama’s presidency, not only illuminated pitfalls in the road he had taken during the previous three years but also directed him down a different, harder-edged, more overtly partisan path that is now defining his reelection campaign.

The meeting that crucial Sunday took place in the office of William M. Daley, the White House chief of staff. Among those in the room were Treasury Secretary Timothy F. Geithner, perhaps Obama’s most influential Cabinet member; Rob Nabors, the legislative liaison; and Jacob J. Lew, then the budget director. Lew had already made the rounds on the Sunday talk shows, saying that Obama was waiting for a negotiating partner to develop a plan to avert the looming fiscal calamity. He betrayed no hint that those elusive partners were coming to the White House that very day.

Lew’s comment referred to the collapse of secret talks a week earlier. Boehner had broken them off after word leaked that tax hikes were on the table. His caucus would not stand for them.

The tea party conservatives, who dominated the group of new House Republicans that gave the GOP a majority in the 2010 elections, were hellbent on preventing Obama from raising the legal limit on government borrowing — known as the debt ceiling — without deep spending cuts and a radical restructuring of expensive health and retirement programs. While its members had elevated Boehner to the speaker’s office, the tea party caucus, critical of Obama’s political agenda and elected to stop it, also proved to be Boehner’s biggest political challenge.

Their voice in the House leadership was Cantor, who also aspired to be speaker and had uneasy relations with Boehner. Publicly, Cantor was insistent that the House would never approve higher taxes. But the White House took his presence now alongside Boehner as a sign that the rift within the GOP had perhaps been patched and that talks could begin again in earnest. “We thought, ‘Okay, this is different,’ ” Daley recalled. “There was a perception from our end that, because Cantor was in the room, the people who blew up the first discussion may be able to be mollified.”

Cantor and Boehner brought their top aides, including Barry Jackson, the speaker’s chief of staff, who had worked in George W. Bush’s White House. When they reached Daley’s office, the Republicans were handed a four-page document that made changes, typed in red, to an offer Boehner had made two days earlier, during a secret meeting at the Capitol.

A lot of red ink, the Republicans thought. But the major elements of a bargain seemed to be falling into place: $1.2 trillion in agency cuts, smaller cost-of-living increases for Social Security recipients, nearly $250 billion in Medicare savings achieved in part by raising the eligibility age. And $800 billion in new taxes.

In Boehner’s offer Friday night, the taxes came with strings attached. The Republicans wanted Obama to give up plans to raise the tax rate paid by the wealthiest Americans, now set at 35 percent. Instead, they wanted that rate to go down. They also wanted to preserve low rates for investment income — one of the biggest perks for the wealthy in the tax code — and establish a blanket exemption from U.S. taxes for corporate profits earned overseas.

Another key caveat: Much of the $800 billion would have to come from overhauling the tax code — not from higher tax rates. The Republicans believed lower rates and a simpler code would generate new revenue by discouraging cheating and spurring economic growth. If the White House would agree to count that money, the Republican leaders said, then they might have a deal.

That last condition was a problem. For years, Democrats have mocked the Republican argument that tax cuts pay for themselves by boosting the economy, an assertion for which evidence is scant. Many independent budget experts say the effect, if it exists, would be almost impossible to measure and useless in crafting a budget. Fiscal “snake oil,” some Democrats say.

So there were issues to work out that Sunday but also reason for optimism. In its counterproposal, the White House appeared to accept the $800 billion tax offer and a lower top rate. The administration rejected the exemption for overseas profits, but Geithner told the Republicans, they said, that he could get most of the way there.

And when Boehner brought up economic growth, arguing that his caucus would not accept tax increases under any other terms, the Republicans saw Geithner as receptive, Jackson said. “It was literally one of the last things discussed when they came in on that Sunday. And Geithner said, ‘Yes, we accept that,’ ” Jackson recalled. “We viewed it as a breakthrough.”

On this point, the two sides are in dispute. Geithner and other administration officials say it never happened. They strenuously deny agreeing to count revenue from economic growth, a process known as “dynamic scoring.”

Treasury spokeswoman Jenni LeCompte said the Republicans “were kidding themselves” if they thought the White House would concede that point. “That’s always been a total non-starter for Secretary Geithner and this administration and always will be,” she said.

Whatever the case, by the time Obama returned to the room with Boehner and Cantor after their half-hour Oval Office chat, the focus was on defending their compromise more than debating it. The president looked at the Republicans and wondered how each side could sell the plan when key components — such as taxes — would need to be explained in ways that would attract liberals and conservatives alike.

“Everybody was saying the right thing,” Daley recalled. “Nobody was saying, ‘If you don’t take this then the deal’s over,’ even though there were real differences. We walked away feeling that we were 80 percent there. But no doubt about it, like any negotiation, the final 20 percent is always the most difficult.”

Jackson said the speaker and his aides felt they had reached a general understanding with Obama and the White House. “Everybody felt really upbeat,” Boehner’s top aide recalled. “They were in nervous territory, as were we. But we walked out of there thinking this was coming together, and we had the outlines.”

That afternoon, the Republican team reconvened at the Capitol, pleased with the morning’s progress. They agreed to drop several key demands.

They would accept fewer cuts in a category of spending that includes federal worker benefits. And they would drop the demands on investment income and overseas corporate profits.

Another major concession: Their offer had proposed boosting the debt ceiling just high enough to see the Treasury through March, which would become the new deadline for Congress to approve the more difficult cuts to entitlement programs and to overhaul the tax code. The White House vehemently opposed that approach. Obama did not want to have this debate again in an election year. The White House wanted a “trigger” that would automatically raise taxes on the wealthy and cut health spending, an idea the Republicans opposed. For now, Boehner and Cantor agreed to give up their demand for a short-term debt-limit increase. But talks on the trigger would have to continue.

“Further discussion necessary to finalize,” Boehner aide Brett Loper wrote in the GOP counteroffer he e-mailed to the White House.

The next morning at the White House, top aides circulated Boehner’s latest offer throughout the West Wing. They met repeatedly in Daley’s office, scouring budget tables and Democratic vote sheets. By mid-afternoon, they told the Republicans that they were about to take a plan to the president for his approval.

A senior administration official said the White House team recognized that the two offers were coalescing and that the time for a decision was at hand. People asked themselves, the official said: Is this something we can sell? Is this a deal we can live with?

At the Capitol, the Republicans waited. Shortly after 6 p.m., Daley called Boehner’s office and said an update was on the way. None came, and four hours later, Jackson told his staff to go home. The White House, he said, was continuing to “massage their counter on all sections.”

The next morning, Nabors called Jackson with an ominous question: Have you heard about the Gang of Six?

Nabors was using the Beltway shorthand for a group of senators — conservatives and liberals — who had been working for months on a long-range deficit-reduction plan based on recommendations from a fiscal commission Obama appointed the previous year.

The group included Sen. Richard J. Durbin (D-Ill.), a close ally of the White House, and Sen. Saxby Chambliss (R-Ga.), one of Boehner’s dearest friends. Another participant, Sen. Tom Coburn (R-Okla.), was close to Obama and Boehner. The senators said they kept Boehner and administration officials informed about their work. They said the White House had been pressing them for months to put something out, believing that getting a few Republicans to sign on to any tax increase would build momentum.

“The fact that we had Republicans willing to discuss revenue was a breakthrough,” Durbin said. “That’s why [the White House] thought it might help move the conversation forward in the House.”

The Gang of Six was unable to seal its own deal. But that morning — a Tuesday — they finally revealed their work at a closed-door briefing for 64 fellow senators. Coming at that moment, it had an unintended effect.

Desperate to resolve the debt-limit deadlock, senators enthusiastically and publicly latched on to the proposal, which included more taxes and stronger protections for the poor and elderly than the still-secret Obama-Boehner framework. Dozens of senators emerged from the briefing praising the group’s work, including Republicans such as Lamar Alexander (Tenn.), then the third-ranking member of his party’s leadership team. The Gang of Six had “come to a bipartisan agreement,” Alexander told reporters, “and I support it.”

At the White House, Obama showed equal enthusiasm. He made a rare appearance in the White House pressroom, surprising reporters who had been awaiting the regular briefing from press secretary Jay Carney. As Carney stood to the side, the president hailed the plan as “broadly consistent with what we’ve been working on here in the White House and with the presentations that I have made to the leadership when they have come over here.”

In private, however, he and his aides were alarmed. The emerging deal with Boehner looked timid by comparison.

“The Democratic leaders already thought we were idiot negotiators,” Daley said. “So I called Barry [Jackson] and said, ‘What are we going to do here? How are we going to sell Democrats to take $800 billion when Republican senators have signed on to” nearly $2 trillion?

Daley added,“I don’t think it was a mischaracterization on our part to say we’d be beat up miserably by Democrats who thought we got out-negotiated.”

In lauding the plan quickly, Obama hoped to harness the enthusiasm for it on behalf of his own talks. But his appearance that day caused more problems by increasing suspicions among conservatives about the group’s framework — and boosting their distrust of any bipartisan dealmaking.

Coburn, a staunch conservative and the only member of his party who openly acknowledged the need for higher taxes to balance the budget, had developed a close personal bond with Obama dating to their shared opposition to federal budget earmarks when both were senators. But Coburn was “shocked,” he said later, when he saw Obama’s remarks that day on television. His effusive praise for the Gang of Six, Coburn believed, was a tactical mistake that revealed Obama’s inexperience in the ways of Washington. It signaled to skittish conservatives that a tax hike was on the way.

Obama’s announcement, Coburn said in an interview, “absolutely killed anything we were doing with the Republicans.”

That afternoon, with concern mounting in the West Wing, Nabors called Boehner’s office with a message from the president: He still wants a deal.

Obama had empowered the aide who knew the Hill best to try to pull it out. Shortly before 7 that evening, he sent a new proposal that, Republicans said they were told, had not been vetted by other senior advisers at the White House. It was his own pitch, underscored by its title: “Deficit Reduction Package — Nabors Draft.”

His plan backed away from earlier positions on taxes in a number of ways, including pushing the top rate below 35 percent. But there was a deal-breaker for the Republicans — a demand for additional tax increases to match proposed cuts to Medicare and Medicaid. To keep the health-care cuts, a critical component of the deal for the GOP, Republicans would have to swallow about $400 billion more in tax hikes — a 50 percent jump from the figure that had been under discussion.

Inside the White House, the offer reflected the new political reality shaped by the Gang of Six. In light of that farther-reaching proposal, White House officials worried that the deal under discussion with Boehner would meet resistance, particularly among Obama’s Democratic supporters. Higher taxes explicitly targeted toward the wealthy offered an element of fairness, in the White House view, and a way to sweeten any deal for the Democratic base.

Obama aides said the new offer also reflected their frustration at what they described as an unrelenting effort by the GOP to cut safety-net programs. “They say: ‘You moved the goal posts. You derailed this entire thing,’ ” said a senior administration official. “But it was simply a recognition of what they were demanding.”

The official said the Republicans wanted “game changers” on Medicare and Social Security; they said they needed an “Obama scalp.”

“We said, ‘Look, guys, in a world in which the Gang of Six just came out today, if you’re doing all those things, a fair and balanced approach involves more revenue,’ ” the official said. “At the time, nobody in the room, neither us nor them, thought that anybody was moving the goal posts.”

The Republicans describe it differently. The news from the White House, they say, was a “tough blow” to Boehner, who saw the push for additional taxes as tantamount to Obama violating a “gentleman’s agreement” on the broad outlines of a plan for which the speaker was already taking heat from some in his ranks.

By Wednesday morning, as the Obama and Boehner sides gathered again in the Oval Office, the optimism of Sunday had disintegrated. Vice President Biden, a skeptic of restarting talks with Boehner after the first round collapsed, was there. There appeared to be a very different president in attendance, as well.

Excited and upbeat three days earlier, Obama now was stern and lecturing. According to notes taken by GOP aides, he opened by complaining about Boehner’s demand for $200 billion in Medicaid cuts, a persistent point of contention. Then he began to talk about taxes, saying the Gang of Six “makes things more complicated.” The White House would need more tax revenue or smaller health-care cuts.

Boehner opened by expressing continued support for a big deal. But he told Obama that Republicans could not sign off on $1.2 trillion in new taxes. “I cannot go there,” he said. Nor could he sell $800 billion in tax increases without cuts to federal health programs, the biggest drivers of future borrowing.

Annoyed, Obama invoked Boehner’s personal friendship with Chambliss, a member of the Gang of Six, warning that Democrats would never support the package under discussion when “your friend Saxby” and other Republicans were willing to stomach as much as $2 trillion in new taxes. Negotiations deteriorated from there.

Boehner said Republicans could accept automatic repeal of the top-end Bush tax cuts as an enforcement trigger only if that were balanced by automatic repeal of a key piece of Obama’s signature health-care law, the individual mandate. Here in the president’s own office, Boehner used the most derisive terminology of conservative critics, calling it “Obamacare.”

Obama laughed. Then he joked that maybe the trigger should be his own removal from office. Biden deadpanned: Republicans might just go for that.

On Thursday morning, aides to Boehner and Cantor gathered again at the White House. During a two-hour meeting, the two sides hashed over minute details of a deal, never actually killing the president’s request for additional tax revenue.

Later that day, Obama called Boehner. The two spoke as if an agreement was still possible.

The Democratic leaders “kind of gulped” when they heard the details, Daley recalled.

By this time, Obama had become the face of the bitter debt-ceiling talks and his poll numbers were dropping. His allies on Capitol Hill cringed at his predicament but also at what he was asking them to do.

“Is there political benefit to coming to a big budget deal with John Boehner? Sure,” Pfeiffer said. “But every other political and message imperative was thrown out the door to prevent a disaster and do the right thing for the country. That’s why we were willing to do things we wouldn’t normally do.”

Reluctantly, Reid and Pelosi agreed to do their best to support the plan.

Boehner, meanwhile, had gone dark.

The House speaker did not return Obama’s call until 5:30 p.m. the next day, a Friday, when he told the president that he was again breaking off the talks. The two men staged dueling news conferences. Obama said angrily that he had been “left at the altar” again. Boehner said dealing with the White House was “like dealing with a bowl of Jell-o.”

“There was an agreement with the White House for $800 billion in revenue,” Boehner told reporters. “It was the president who walked away from this agreement.”

Two day later, July 24, one week after the Sunday morning meeting that sparked such optimism, the president found himself trying to turn back the clock.

Working late into the evening, Obama asked someone to get Boehner on the phone. His message: I’ll take your last offer.

“Mr. President,” Boehner answered, “we don’t have time to reopen these negotiations.”

White House officials said this week that the offer is still on the table.

The following night, Obama delivered a prime-time address from the East Room to update Americans on the status of the talks. He left no doubt about whom he intended to blame for the failure of the grand bargain.

The only reason a deal is not on its way to becoming law, he said, “is because a significant number of Republicans in Congress are insisting on a different approach — a cuts-only approach — an approach that doesn’t ask the wealthiest Americans or biggest corporations to contribute anything at all.”

In the following days, congressional leaders and Obama worked out a bare-minimum agreement to lift the government’s borrowing limit just enough to get past the election.

The tough choices on deficit reduction were handed to a special House-Senate “supercommittee,” and if that group failed to secure legislation by the end of 2011, then the deal required $1.2 trillion in automatic, across-the-board cuts to agencies, including the Pentagon.

Although Obama had denounced “kick the can down the road” deals as a candidate in 2008, he was now adjusting to the realities of his office. The agreement was at least a tactical victory. He used it to wash his hands of Washington’s dysfunction, presenting himself as a well-intentioned man unable to secure a fair deal, because of the capital’s enduring partisanship.

But White House advisers conceded that the collapse of the debt talks was a disaster from a policy perspective and, at least in the short term, from a political one. For the first time, Standard & Poor’s, the credit rating agency, downgraded U.S. debt. Polls showed that the public blamed Obama as well as congressional Republicans, with approval ratings for both reaching new lows.

In mid-August, Obama escaped for a week of golf and relaxation with his family on Martha’s Vineyard. He reviewed his strategy, concluding that it was time for a dramatic shift in approach. With the debt-ceiling debate over, he would focus more fully on jobs, the chief concern of most Americans, including his Democratic base.

At the White House, economic advisers who had devoted so much time to meeting with House Republicans now turned their attention to drafting the American Jobs Act, a package that would extend a temporary payroll tax holiday, provide fresh money for roads and bridges — and set up a new confrontation with Republicans.

“You say you’re the party of tax cuts? Well then, prove you’ll fight just as hard for tax cuts for middle-class families as you do for oil companies and the most affluent Americans,” Obama said to thunderous applause at a Labor Day speech in Detroit. “We’re going to see if congressional Republicans will put country before party.”

Suddenly, the same Democrats who had accused Obama of meekness in negotiating with the GOP were praising his aggressive new tone. What happened during those days in July when the grand bargain was almost reached, but not quite, had changed him. He no longer seemed divided.