WASHINGTON -- Barack Obama and Harry Reid needed to clear the air. The relationship between the president and the Senate majority leader had been deteriorating since 2011, with Reid losing respect for Obama's ability to negotiate with Republicans and Obama unsure if Reid had as much control over his Senate Democratic caucus as he liked to say.

So at the White House's invitation, the two met in the Oval Office on July 9, with no staff, to talk one on one. It was a cathartic moment, one in which long-buried tensions were fully aired. Aides to the two men tell a similar story: Their boss had been losing confidence in his counterpart and wanted the meeting as a way to buck up the other.

Reid (D-Nev.) pressed the president hard on the 2011 debt ceiling compromise that the White House had cut with the GOP, which ultimately gave the country sequestration. He complained that Vice President Joe Biden had undercut fiscal cliff negotiations at the end of 2012, when Senate Minority Leader Mitch McConnell (R-Ky.) was offered a more generous deal on tax revenue and sequester spending than Reid felt he could have crafted.

It didn't escape his notice, Reid said, that the deal Biden made conveniently postponed the budget cuts two months, or just long enough to allow the Inauguration and the State of the Union address to pass without the sequester's shadow. Senate Democrats had been pushing for a two-year delay and had been prepared to settle for just one.

Now, in July of this year, the country was feeling sequestration's effects. Head Start classes were shuttered, scientific research imperiled, cancer treatments hampered, and the broad concept of functioning government was under assault.

The president said that he, of course, was unhappy with the various outcomes, but had to deal with different political realities. The message of the 2010 midterm elections had been that the country wanted him to work more closely with Republicans. And when it came to the ending of the Bush-era taxes, he had to uphold his pledge that the middle class would not see a hike. More generally, he worried that the Senate Democratic caucus would end up fractured if the party pushed too hard, leading the administration to cut deals directly with McConnell.

It was a painful jab at Reid, who takes pride in his ability to hold his broad caucus together on even the most fraught legislative battles. "If you're ever wondering if I can hold my caucus, just ask me," he told Obama.

The Huffington Post put together the story of that critical meeting and the subsequent standoff negotiations through interviews with Reid, White House advisers and congressional leadership aides.

Asked about the meeting the day after the 16-day government showdown was resolved, Reid acknowledged the disagreement over the 2011 debt ceiling strategy. Pausing for a few seconds, he reflected on how his relationship with the president has evolved.

"President Obama is such a nice man, just a nice person. And he became president during an awful time," Reid told HuffPost, measuring each word. "It is easy to look back and say, 'Oh, he shouldn't have done that, or he shouldn't have renewed the payroll tax.' That's all then, this is now. A different environment. I don't want to sound like a cheerleader for Obama. He can get others to do that. But he's a good person."

That July meeting ended up being just what the two needed. "That was good," Reid would tell his chief of staff, David Krone, who'd been waiting outside with top White House aide Rob Nabors. It helped lay the groundwork for what would be a critical -- and fruitful -- political partnership during the high-stakes budget fights this fall.

Each more mindful of the other's strategic vision, Reid and Obama made a mutual commitment to legislative stubbornness. A week after the meeting, Reid threatened to gut the filibuster if Republicans didn't let through a slate of executive nominees. Republicans caved. Looking forward, the two vowed to steadfastly oppose any effort to tinker with the president's health care law as part of a continuing resolution to keep the government running. And when it came time to raise the debt ceiling weeks later, they would refuse to negotiate altogether.

Through the first government shutdown in 17 years and a near-breach of the nation's debt limit, they followed this playbook until it ultimately resulted in a Republican collapse.

"We just both came to the conclusion that the time had ended to be taken in by these crazy people," Reid said. "The president said, 'I'm not going to negotiate.' I said, 'I'm not going to negotiate.' And we didn't."

*****

During the late summer and early fall, the durability of the Obama-Reid pact would be repeatedly tested. Toward the end of August, the two men checked in again on a conference call. With the showdown over the debt ceiling and budget visible on the horizon, Reid wanted to know just how far he and his caucus should go. The daunting responsibility not to default rested with the president, Reid said, but if the president was willing to fight to the end, so were Senate Democrats.

I'm all in, the president assured him.

As the October deadline to fund the government approached, both sides momentarily assumed that fight would be avoided altogether. House Speaker John Boehner (R-Ohio) had made an informal agreement with Reid to accept a funding level of $988 billion, which would extend only for a matter of weeks. All indications suggested that Boehner would follow through, with only a ceremonial vote to defund Obamacare. In fact, one senior administration official told The Huffington Post that their main concern in the days leading up to the end of September was that McConnell, not Boehner, would buckle under pressure from his caucus.

But as the weeks counted down, the White House grew convinced that the deal would blow up, as Boehner looked to be caving in to demands to defund Obamacare.

On Oct. 1, the initial day of the shutdown, the scene inside the White House was chaotic. While the entire staff came in that morning, a sizable chunk were forced to leave hours later -- BlackBerrys turned off -- as "non-essential employees." Normal operations were upended. But the administration assured Hill Democrats that the political message remained the same: They weren't budging.

In fact, the White House was so concerned with getting the message across that a meeting was called with McConnell, Reid, Boehner and House Minority Leader Nancy Pelosi (D-Calif.) on Oct. 2, after aides privately heard from reporters that Republicans thought the president was bluffing. During that session, the president assured the speaker that his intransigence was sincere. A sullen Boehner, leaving the meeting before anyone else, complained to the waiting press corps that Obama was being unreasonable.

"It was basically all of them saying over and over again that they were not going to negotiate," a top Republican House aide briefed on the meeting told The Huffington Post. "The speaker didn't have to say a whole lot."

By that point, both Hill Democrats and White House aides had grown convinced that the shutdown would last as long as it took to raise the debt limit. Boehner couldn't capitulate two times in three weeks, their theory went, so he would combine the two together.

On Oct. 10, the president held a meeting with Senate Democrats to discuss the state of play. No one in the room questioned Reid and Obama's decision to draw hard lines over the continuing resolution and debt limit. Obama, in return, assured the caucus that he had told Boehner in previous gatherings that the $988 billion price tag to fund the government was "a floor, not a ceiling."

But concerns were creeping in that the standoff could actually lead to a debt default. The president was pressed by Senate Majority Whip Dick Durbin (D-Ill.) to reconsider the so-called constitutional option, which would have him invoke the 14th Amendment as a way to unilaterally raise the debt limit. Obama called it unworkable. He then made light of a second escape-hatch proposal -- the idea that he could mint a trillion-dollar coin -- before reminding attendees that the Federal Reserve had ruled that one out, too. The Treasury Department had explored every creative option conceivable, he added, and some were better than others. But all of them were bad, and he was declining to talk about the possibilities in the hopes they could all be avoided.

Obama tried to buck up Democrats by spinning the 2011 debt ceiling deal as a victory. "Jack and Rob took them to the cleaners," he said, according to a source in the meeting, referring to then-presidential advisers Jack Lew and Rob Nabors. "We let them say they had a victory, but Democrats also believed it."

For his own part, Obama was not completely confident that calamity would be averted. He confided to the senators that he was taken aback at comments from Sen. Richard Burr (R-N.C.) downplaying the significance of blowing through the debt limit. He expected that from the real ideologues like Sen. Tom Coburn (R-Okla.), he said, but not from a Republican who represents North Carolina, where Bank of America is headquartered. Later, he would note the oddity that one party could house both financier Warren Buffett, who called defaulting on the debt "a pure act of idiocy," and freshman Rep. Ted Yoho (R-Fla.), who had declared days earlier that not raising the debt ceiling "would bring stability to the world markets." (Just how Republican Buffett actually is remains a matter of debate.)

Behind the scenes, administration officials were pulling any lever they could. They called business leaders, Republican lobbyists and GOP wise men to solicit ideas on how to move Boehner. They pleaded with them to call Republican congressional offices as well. (Obama told the Senate Democrats that one CEO, who went unnamed, was refusing to return Boehner's calls, angry at his alliance with the tea party.) The president recognized that the GOP wanted what he called "a bloody shirt" in exchange for funding the government and raising the debt limit. But their demands were outlandish to the point of being laughable: At a meeting with House Democrats, Obama joked that the Republican ransom list was so long, the only thing it didn't include was his resignation. And even if the demands had been reasonable, he had resolved on principle not to meet them.

Then, a glimmer of hope. The same day that he sat down with Senate Democrats, the president held a meeting with top House Republicans.

According to interviews with aides from both camps, the gathering started off like the prior ones. As Republican after Republican suggested possible outlines for a deal, the president offered the same rejoinder: "I don't understand why the government needs to stay shut while we do these negotiations," he would say. "Tell me why the government needs to stay shut."

At one point, a frustrated Boehner shot back, "Your position is risking default." But eventually, the two sides began talking shop. House Budget Committee Chairman Paul Ryan (R-Wis.) floated the possibility of raising the debt ceiling for six weeks and then quickly crafting an agreement to reopen the government. The administration thought it was a trap and grew even more suspicious when Ryan let slip that during those six weeks the two parties would negotiate over raising the debt limit once again. But the administration agreed to entertain offers from Ryan and others over how to get the government reopened.

Later that night, in staff-level discussions, the sides began considering a trade. In exchange for further means-testing of Medicare benefits, as well as reform of federal workers' pensions and Tricare health benefits for veterans, House Republicans would give Democrats $100 billion in sequestration relief over two years and open the government that Monday.

Nabors was intrigued that sequestration relief was on the table. But he thought the price tag was too high. Republicans, too, weren't sure that they could sell it to their caucus and suggested that they'd need to add some "sweeteners" to the package. They came back with two: a provision allowing private insurers and employers to not cover contraception in the health plans they offered and a pause on all new federal regulations.

"That's not happening," Nabors replied.

The next morning, nevertheless, he took the basic outline of the negotiations to White House Chief of Staff Denis McDonough, Office of Management and Budget Director Sylvia Burwell and top presidential adviser Dan Pfeiffer. The three of them briefed the president at around 11 am. Obama considered it a good faith offer but not one he could accept. After federal workers had been forced off the job, it would be particularly cruel to find a resolution to the shutdown in the form of decreasing their pensions. Moreover, he was concerned about any trade of permanent entitlement reform for temporary spending bumps. Even if he did like the offer, however, he couldn't sell a package like that to congressional Democrats unless it included a revenue increase.

"Harry and Nancy will need revenues," Obama told Boehner during a call on the afternoon of Friday, Oct. 11. He added that he wouldn't send a counteroffer -- after all, his principle was not to negotiate -- but he'd look at any revamped ideas that the speaker had.

Nothing ever came.

*****

On Reid's front, meanwhile, things were buzzing. Senate Republicans had been privately coming to him expressing interest in crafting a deal. As the deadline neared, Sen. Susan Collins (R-Maine) took the lead in finding a way through the impasse.

Behind the scenes, the White House and Reid grew anxious that lawmakers would jump at the opportunity to play doomsday savior. Administration officials thought the Collins plan was actually a worse offer than the one Ryan had floated days earlier, because it locked in sequester-level spending for half-a-year. Nabors and McDonough began calling moderate Democrats, urging them to get "back in the box."

Collins' lead negotiations partner, Sen. Joe Manchin (D-W.Va.), continued making noise about forging ahead despite the leadership rejection. But the other Democrats working with Manchin kept their involvement largely private. It was a reminder that the new Senate Democratic caucus is easier for Reid to control, which he did, easily.

"My goal was to maintain cohesion with my caucus and the White House," Reid said. "That was my goal, and I'm sure that was the president's goal. Now my caucus is just as varied as a caucus could be. I have Bernie Sanders, I have Mary Landrieu. I mean, they have different interests in the world. But they had had enough of this."

Eventually, Reid put a public dagger in the Collins talks, declaring that her deal was "not going to anyplace at this stage." But the emergence of a bipartisan way out of the impasse -- the type of plot development beloved by the political press -- had tested the Reid-White House alliance. Senior staff began whispering doubts about the other side's fortitude.

"I do fear the White House is up to something bad. [Obama] says over and over, 'I won't negotiate,' but we know he loves to cave," one Senate leadership aide told HuffPost, sparking an angry White House reply. "One of the rituals of these fiscal showdowns is the practice of some anonymous Senate staff suggesting that the White House is getting soft," said a White House staffer.

Reid, during the post-crisis interview, said he had been aware of the staff tensions. "My staff, his staff were not working together -- not on purpose, but, you know, people just get carried away with what they do," Reid said.

Anonymous quipping between Reid and Obama's teams had occurred during tense legislative standoffs in the past. During the crafting of health care reform in 2010 and the debt ceiling standoff in 2011, top aides launched repeated barbs at the other through a readily compliant press. (Then-White House Chief of Staff Rahm Emanuel once flipped off then-Reid spokesman Jim Manley in 2010.) But those battles also hardened each camp. As they entered round three this time, the bickering stayed largely in check.

"The fact is that Senator Reid was more than a little upset in 2011 when the president and his team kept on trying against all odds to cut a deal on a so-called grand bargain," said Manley, Reid's former top spokesman. "But that was then and this is now … The interests of both Senator Reid and the president were perfectly in sync this time."

Time was still running short. With no plan coming from the House and with the Collins option tabled, talks began picking up between Reid and McConnell. A week before the debt limit deadline, the two leaders deputized Sens. Chuck Schumer (D-N.Y.) and Lamar Alexander (R-Tenn.) to chart a legislative path forward. They chatted three times the next day. At one point, Alexander approached Schumer in the Senate gym. Working out on an exercise bike, Schumer told him that Democrats simply could not agree to a bill that extended sequestration funding past Jan. 15. Alexander agreed to trim down the length of the continuing resolution.

On Oct. 12, the Saturday before the deadline hit, the four senators met at 9 a.m. According to a Senate Democratic aide, McConnell was "very engaged" during the meeting, clearly wanting to get the standoff behind him. By Sunday, the "nucleus" -- as their staff called them -- had a framework in place. Throughout the next day, staff began hammering out the bill's details. The president placed a call to McConnell to keep abreast of the progress.

And then, everything stopped. Worried that his House caucus would get jammed by the Senate, Boehner pressed McConnell for time to try his hand once again. The speaker was juggling the demands of multiple factions. His moderate members had been complaining in private that the standoff was crushing them. But they hadn't bolted, much to the delight of the conservative wing. "At one point," a senior House GOP aide said of one caucus meeting, "Michele Bachmann stood up and thanked the moderates for standing with us."

With the sense that he had his full caucus' backing, Boehner put together a final offer that funded the government and lifted the debt ceiling, while ending the federal health care contributions for members of Congress and delaying Obamacare's medical device tax.

It was another bit of defiance against Obama's demand that reform of his health care law was off the table, and despair began to set in at both Reid's office and the White House. One senior administration official said concerns heightened that Tuesday that the country would default. Reid shared the fear.

"Oh, yeah," he said when asked if there were moments he thought the country would hit the debt limit. "Oh, yes. Absolutely, absolutely. People were giving speeches that it wouldn't hurt anything. Of course there was worry. I was trying to be logical and rational dealing with illogical and irrational people. I was damned scared."

But Democrats held firm. With Pelosi denying Boehner a single vote from her caucus and too many conservatives defecting, the speaker's last-ditch gambit didn't even reach the floor. He agreed to let the House vote on whatever the Senate came up with. “You gave everybody a shot," Pelosi told Boehner over the phone, referring to his efforts to try every plan the tea party proposed. "Now, you’re going to give Congress a shot."

It was an embarrassing setback in a standoff filled with them. And it left McConnell with no leverage at all. The minority leader gamely tried to pull a concession out of Reid, presenting an offer on Tuesday night that would raise the debt ceiling and fund the government in exchange for a delay in the medical device tax, an end of the Treasury Department's use of extraordinary measures to stave off default, and income verification for Obamacare subsidy recipients.

Reid dismissed it out of hand.

Ten minutes later, McConnell called back asking only for income verification. The deal was done. The pact of obstinacy that Reid and Obama struck had paid off.