House Speaker John Boehner couldn't hold back when he spotted Senate Majority Leader Harry Reid in the White House lobby last Friday.

It was only a few days before the nation would go over the fiscal cliff, no bipartisan agreement was in sight, and Reid had just publicly accused Boehner of running a "dictatorship" in the House and caring more about holding onto his gavel than striking a deal.

"Go f-- yourself," Boehner sniped as he pointed his finger at Reid, according to multiple sources present.

Reid, a bit startled, replied: "What are you talking about?"

Boehner repeated: "Go f-- yourself."

The harsh exchange just a few steps from the Oval Office -- which Boehner later bragged about to fellow Republicans -- was only one episode in nearly two months of high-stakes negotiations laced with distrust, miscommunication, false starts and yelling matches as Washington struggled to ward off $500 billion in tax hikes and spending cuts.

The White House and Congress knew of the self-imposed deadline for more than 17 months and they still blew past it, as a president fresh off a strong reelection victory tested -- and ultimately broke -- the Republican Party's fidelity to its tax-cuts-only governing philosophy.

It took a late intervention of two Senate veterans -- Senate Minority Leader Mitch McConnell (R-Ky.) and Vice President Joe Biden -- to rescue the negotiations. Their relationship, forged over two decades on Capitol Hill, helped move Congress to a resolution because it wasn't burdened by the raw political conflicts of the past and the legislative fights still to come.

But even those longtime Washington hands couldn't prevent a New Year's Day drama in the House. Boehner weathered a revolt against the bill, which played out during two meetings in the Capitol basement in which his fellow GOP lawmakers lashed out at having to accept the measure without spending cuts.

After hours of uncertainty -- even insults against "sleep-deprived octogenarians" from the Senate who passed the bill in the dead of night -- the House gave final approval to the deal, 257-167. It was carried by 172 Democrats and 85 Republicans. And it exposed another split: Boehner voted yes, but his top deputies, Majority Leader Eric Cantor of Virginia and Majority Whip Kevin McCarthy of California, voted no.

This account of the behind-the-scenes drama that pushed the nation to the brink was drawn from dozens of interviews with key players at the White House and in Congress who were directly involved in the talks. The look back reveals a tumultuous two months as the country's top leaders stumbled -- some would say blundered their way -- toward an agreement.

Obama pushed forward despite strong reservations expressed by top congressional Democrats -- especially Reid -- who privately described it as a "bad deal" that would increase Republican leverage in future budget fights. Democrats were especially furious with Biden's handling of the final major sticking point, believing that he was too quick to offer a short-term delay of the across-the-board spending cuts known as the sequester.

Just hours before the Senate overwhelmingly approved the bill, Reid called Obama and told the president he had serious concerns.

Reid figured Democrats could get a more favorable agreement if they waited. When Reid saw an offer that Obama had considered pitching to McConnell on Sunday, which included provisions opposed by Senate Democrats, the majority leader crumpled up the document and tossed it into the burning fireplace of his Capitol office.

But Obama decided not to walk away from negotiations, despite earlier claims by his aides that he would be willing to go over the cliff. Biden emerged as a key voice in encouraging the president to stay on track with a deal.

The president did not believe the dynamic would suddenly shift in his favor after Jan. 1, rejecting the conventional wisdom in Washington that all sides would have more flexibility after higher tax rates took effect. Republicans were no more likely to compromise after the deadline than before it, the White House concluded. And there was a very real fear that a resolution wouldn't come for weeks, perhaps not before the country hit the debt limit in late February -- a nightmare scenario that the president believed would destroy not only his leverage but also the still-fragile economy.

The chaos on New Year's Day in the House validated the president's strategy to find a solution now, White House aides said.

Despite the ugly process and bruised relations, the West Wing thinks it won big.

"Today's agreement enshrines, I think, a principle into law that will remain in place for as long as I am president," Obama said after the House voted. "The deficit needs to be reduced in a way that is balanced. Everyone pays their fair share. Everyone does their part. That is how our economy works best. That is how we grow."

The bipartisan package allows taxes to rise on American households for the first time in a generation, marking a 180-degree Republican shift from the 2011 debt limit showdown when the GOP balked at closing corporate jet loopholes worth a couple billion dollars. The bill is a wild swing: It raises revenue by $620 billion and cuts spending by only $12 billion.

But the failure to address several big issues sets up another fiscal showdown in late February, when the two-month delay in the sequester coincides with the deadline to raise the country's $16.4 trillion debt limit.

The pact also does little to reduce trillion-dollar-plus deficits, shore up entitlement programs, overhaul the tax code or stimulate the U.S. economy -- the casualty of a polarized political culture that scorns compromise.

Not only was there deep suspicion between Boehner and Reid -- as illustrated by the expletive-laced confrontation in the West Wing -- Obama and Boehner still didn't trust each other enough to land the big deal. Each thought the other lacked the leadership skills to forge a "grand bargain" and take on the vocal wings of his own party.

White House officials were furious with Boehner for in their view breaking off the grand bargain talks in mid-December -- the second time in two years that he had abandoned negotiations with Obama. And they were mystified by the speaker's next move. He decided to go it alone on a "Plan B" bill that forced Republicans to raise taxes for the first time in a generation but held little chance of becoming law because of Democratic opposition. Boehner's aides say they were trying to instill urgency in the Senate.

The frustration was mutual. Boehner's top policy aide, Brett Loper, yelled at White House economic adviser Gene Sperling for not offering Republicans any plans to avert the fiscal cliff. When Treasury Secretary Timothy Geithner delivered an offer to Republicans that they found laughable, GOP aides quickly leaked all the details to reporters.

Boehner and his top aides did not feel that Obama was negotiating in good faith. At several points, when they thought they were starting to make progress, they accused the president of "shifting the goal posts."

McConnell and Reid, who have prided themselves on working well together, couldn't get along this time, either.

The bad blood was evident from the start. When Obama sat down for an opening meeting with congressional leaders on Nov. 16, McConnell attacked Reid over the majority leader's proposal for filibuster reform, an issue that had nothing to do with the fiscal cliff talks. The broadside stunned others in the room.

When the two Senate leaders attempted to reach a deal last weekend, McConnell didn't think Reid was truly invested in the process. Reid was leery of how many votes McConnell could deliver.

Even the usually close alliance between McConnell and Boehner nearly unraveled over disagreements on strategy. Senate Republicans became convinced that House conservatives would sink the economy and their party by refusing to sign off on a bipartisan agreement, a fear that grew only more pronounced during the chaos on Tuesday.

But almost two months earlier, things seemed to start on a promising note.

Boehner saw the election results and decided that he needed to deal. Hoping for a bipartisan agreement, he offered $800 billion in new revenues by closing tax loopholes, not raising rates. It was a major step: No Republican leader had gone that far in more than two decades, and Boehner risked a conservative backlash.

"This is where I'm going," Boehner told Cantor and other colleagues, who gave him the green light.

Obama and Boehner agreed to streamline the negotiations and engaged in direct, one-on-one talks.

The president asked Geithner, rather than White House chief of staff Jack Lew, to serve as his chief negotiator. The move pleased Republicans who hadn't liked Lew's negotiating style during the 2011 debt limit talks. But that wasn't the main reason Lew was kept out of the spotlight: As a top choice to replace Geithner at Treasury, Obama was "saving him," reluctant to embroil him in tense negotiations if he needs the Senate to approve his nomination.

Despite Boehner's opening gambit on taxes, the negotiations didn't take off.

Much to Boehner's chagrin, the first offer from the White House didn't come until after Thanksgiving. And when it did, Republicans were stunned. Obama sought $1.6 trillion in new revenues, while offering only $600 billion in spending cuts.

By early December, with talks barely moving, Obama was using his bully pulpit to win the public opinion fight, holding campaign-style events in key states and aggravating Republicans. Privately, he began calling moderate Republican senators he kept on a list in an effort aimed at raising pressure on their leaders.

Republicans began to fret about losing the PR fight. In a closed-door meeting, some GOP House lawmakers suggested that each member kick in $5,000 to hire a big Madison Avenue advertising firm to craft a communications strategy for them. But Boehner and other party leaders quickly shot down the idea.

The actual negotiations were no less worrisome. "The president says good things to Boehner, and then Nabors and Geithner always follow it up with something absurd," said one senior House Republican leadership aide. "It's excruciating."

Obama raised the stakes during a Dec. 13 meeting with Boehner.

The president -- speaking for 45 minutes in a 50-minute meeting, Republicans said -- suggested they could find a middle ground but warned that if they did not, he would use his inauguration address, State of the Union speech and every other lever of power to lash Republicans.

Boehner urged Obama to return to the offer Obama made during the 2011 debt limit fight, which would have raised $800 billion in revenue, but not by boosting tax rates. The president refused, believing his strong electoral victory had altered the political landscape.

There were two doors the two parties could walk through, Obama told Boehner and other top aides in the Oval Office that day. Door No. 1 led to a bipartisan agreement and they would all be hailed as heroes, Obama said, although he added that liberal economists like Paul Krugman would claim, "I've been fleeced again." Door No. 2, on the other hand, led to impasse and a daunting set of consequences: high interest rates, a credit downgrade and a worldwide recession.

A day later, as the country learned of the mass killings at a Connecticut elementary school, Boehner called Obama with a major concession: Republicans would let tax rates expire on income above $1 million.

But when details of the offer leaked to POLITICO before Boehner could frame it on his terms, conservatives turned on the speaker.

Meanwhile, McConnell, worried about the fallout for Republicans if there were no deal, was privately floating a "two-bill strategy" -- one to extend the current tax rates for everyone and another to allow taxes to increase on the wealthiest Americans. That infuriated House Republican leaders, who believed McConnell was undermining their talks with Obama. Some House Republicans mistrust McConnell more than they do Obama or Reid because they are confident they always know where Democrats stand, unlike the Kentucky Republican.

By Dec. 17, history began repeating itself.

Obama called Boehner with a counteroffer that included boosting the threshold for tax increases to Americans making more than $400,000 -- a major concession, since he had campaigned on the $250,000 limit -- but Cantor and other top Republican leaders wouldn't accept it.

So the speaker prepared a fallback option, announcing the next morning that he would ask the House to raise tax rates on income above $1 million -- and do nothing else. There were be no spending cuts and no effort to address the sequester. Boehner dubbed this his "Plan B" proposal.

The move confounded and infuriated the White House, although it didn't surprise them that Boehner decided to walk away from negotiations. They were always worried about his ability to corral his conference.

Boehner publicly stated that he would continue negotiations with Obama, but the two men did not talk for the rest of the week while the speaker burned four days on the clock. His members refused to take up the bill.

In a phone call Dec. 21, Boehner told Obama that his game plan all along was to pass the bill setting the $1 million threshold, send it to the Senate to drop it down to $500,000 or so, and ship it back to the House for approval.

Obama, perplexed by the secret strategy, asked Boehner whether he had shared it with Reid or House Minority Leader Nancy Pelosi (D-Calif.), suggesting that they might have helped him. Boehner said he had not.

At that point, the West Wing saw only two scenarios for even a minimal deal: The Senate needed to come up with a bipartisan compromise or Democrats would jam through Congress the president's initial plan to set the income threshold at $250,000.

When Reid and McConnell took control of the talks after Christmas, there wasn't much optimism -- a sentiment that proved prescient when they abandoned talks by Sunday afternoon. They hit an impasse when Democrats objected to a McConnell proposal that would have resulted in lower Social Security payments.

That's when Biden, who had been kept on the sidelines from the start, came off the bench at McConnell's urging.

During their first call, Biden stalled, saying he was "not up to speed" on the status of the talks. Democrats privately snickered that McConnell "is calling his dad for help." But Democrats also knew Biden's presence made a deal much more likely.

Reid grew frustrated. McConnell had lowered his income threshold target from $750,000 to $450,000. But the Democratic leader -- who wanted to push back the sequester for two years -- didn't like the short, two-month delay.

Reid told Obama that if the White House wanted Senate Democrats on board, the officials had better do it themselves.

And so the White House did. Biden made a late-night, New Year's Eve visit to Capitol Hill, and his sales pitch to his former colleagues won them over. The Senate approved the bill, 89-8.

But just when it appeared the nation had averted calamity, New Year's Day brought a fresh obstacle. Liberals and conservatives in the House both hated the deal. Biden made a return trip to the Hill to calm his restive allies. Boehner -- left without political cover by his Republican colleagues in the Senate -- struggled to find a resolution in his own caucus.

After a frantic day that seemed likely to end with no deal, Boehner gave his members a choice.

The House Republican Conference could attach spending cuts, which would likely kill the bill -- and leave them shouldering all of the blame for the largest tax hike in American history. Or they could vote up or down on the Senate bill.

They chose the latter.