The story of Capitol Hill’s week on the brink — which brought Washington within an hour of a government shutdown — is a narrative of three men, each with a confining sense of his own limitations.

House Speaker John A. Boehner (R-Ohio) entered budget negotiations at the head of a rambunctious Republican majority. Quietly, though, he worried that conservative lawmakers might desert him if the deal he struck didn’t meet their expectations.

President Obama had his own problem: He was trying to change his public image in midstream, from America’s top Democrat to a chief executive immune from partisan squabbling.

Senate Majority Leader Harry M. Reid (D-Nev.) had watched his party lose its momentum. For all his power, his job had shrunk to defending Democrats’ past gains.

Last week, their first big public fight since Republicans took over in November played out in 3 a.m. meetings, angry press conferences and tense sessions at the White House — which hit their boiling point late Thursday night when Vice President Joe Biden lost his temper at Boehner. It ended with a late-night handshake at the Capitol and Republican cheers in a crowded basement.

The detailed story of that week — relayed Saturday by aides invested in portraying their man as the hero — shows that all three were trying to camouflage weaknesses with bluffing and public confidence. They settled only in the face of a shutdown — the one thing they feared more than giving in.

In the end, Boehner got the huge budget cut conservatives wanted. Obama got to take credit for bringing the sides together. And Reid got a chance — in a dispute over funding for women’s health groups — to rally a beleaguered Democratic base.

Outside the White House and Capitol, their long staredown had a serious cost.

For days, a city had been creakily, and expensively, preparing to shut itself down. And a country had watched in amazement: Was the U.S. government really fighting over whether to reauthorize itself?

Boehner’s problem

For Boehner, last week was a chance to prove his toughness, and conservative bona fides, to the fractious Republicans he leads.

His problem had been made clear a month ago. The House was set to vote on a stopgap budget to keep the country running, but 54 members of his caucus pressed the red button for “no.” The bill passed, but they sent Boehner a message: He didn’t have the unqualified support of all 241 House Republicans.

“If you don’t have 218, you’re not speaker,” one of Boehner’s close friends said, adding that they “cut his legs off.”

The roots of Boehner’s problem stretched back to last fall’s elections, which propelled him to power. On the campaign trail, Republicans promised that they would cut $100 billion from Obama’s budget proposal.

Now, there were 87 new freshmen in the Capitol, and many of them believed that would happen.

But it was a promise Boehner couldn’t keep. Democrats in the Senate rejected it out of hand.

As the last week began, Boehner was determined not to seem wobbly. In private meetings with Democrats, he repeated a mantra: “Nothing will be agreed to, until everything is agreed to.”

And so, nothing was.

Who’s essential?

As a shutdown drew closer, Office of Management and Budget employees began to work late nights, scarfing Five Guys burgers and cold, wilted french fries. The questions came in: Will I be paid? Can I still use my BlackBerry if I can’t come to work?

Unclear, they said. And no.

Other agencies began an awkward sorting process. Who was “essential,” and would work in a shutdown?

“Any furlough is not a reflection on you or your performance,” Labor Secretary Hilda Solis wrote in a memo, hinting at the sting of being “nonessential” in a town that defines people by their work. “I value every single one of you and the work you do.”

Outside Washington, the assignments seemed even more surreal. At Mojave National Preserve in California, workers warned visitors they’d have to leave within 48 hours of a shutdown.

Not that anyone would notice.

“If we were furloughed, we wouldn’t have the staff to find them anyway,” park employee Danette Woo said.

‘This is it’

As the stalemate dragged on into Thursday night, President Obama summoned both Reid and Boehner to the White House. All week, Obama had sought to appear as Washington’s peacemaker, not as a partisan warrior on the Democratic side.

But there was a problem: Boehner wouldn’t give in and make peace.

With almost 24 hours to go until the government shut down, Obama gave Boehner an ultimatum on the speaker’s push to include abortion-related restrictions in the bill.

“John, I will give you D.C. abortion. I am not happy about it,” Obama said, according to a Democrat and Republican in the Oval Office. Boehner had been pushing to include both the restriction of government funding on abortions in the District of Columbia and a provision that would have placed limits on funds going to nonprofit groups that provide abortion services nationwide, including Planned Parenthood.

With the D.C. provision in hand, Boehner continued to push the president, aides said.

“Nope, zero,” Obama told Boehner. “Nope, zero. John, this is it.”

And that was it — for a little while. Later, White House aides said, Boehner returned to the issue. Evidently, he had pushed Biden too far.

If Republicans didn’t buckle on this provision, an angry Biden warned, “We’re going to have to take it to the American people.”

Nonetheless, they were close to agreeing to a dollar amount, or so the White House thought. By the next morning, though, White House aides said Boehner’s staff appeared to be asking for more cuts.

So Obama called Boehner. Where Biden had been threatening, Obama tried to appeal to Boehner’s sense of responsibility.

“I am the president of the United States and you are the speaker of the House. We are the two most consequential leaders in the U.S. government. We had a discussion last night and the staff negotiations don’t reflect that,” Obama told Boehner, according to White House staffers.

“The president believed Speaker Boehner was always there,” in understanding the gravity of the situation, a senior Obama aide explained. Boehner “did not want this to come to a shutdown.”

Reid’s voice

In the last days of negotiations, Reid suddenly found an issue — and a voice.

To that point, Boehner seemed to be the driving force behind the negotiations. In February, for instance, Reid’s spokespeople had denounced a proposal to cut $4 billion as “reckless” and “extreme.” Two days later Reid reversed course and embraced the cuts.

This was a continuation of troubles that had left the majority leader politically weakened. Reid won reelection in 2010, but only after a close-fought campaign against a political neophyte. His party held the Senate, but its share of seats has shrunk from 60 in 2009 to 53.

After the midterms, some of Reid’s leadership duties were transferred to Sen. Chuck Schumer (D-N.Y.). At a press conference Friday, Schumer stood behind Reid and could be heard coaching him on how to answer reporters’ questions.

But as the Planned Parenthood issue emerged as a key sticking point, Reid took the spotlight.

“The numbers are extremely close,” Reid said Thursday morning. “If this government shuts down, and it looks like it is headed in that direction, it is going to be based on my friends in the House of Representatives, the leadership over there, focusing on ideological matters that have nothing to do with funding the government.”

Immediately, his own caucus rallied behind him. Democrats raced to the floor one after another denouncing the Republicans for threatening to shut down the government over abortion politics. Female Democratic senators held press conferences, and at one point Friday Democratic staff set up a podium off the Senate floor so that they could hold rolling press conferences attacking Republicans.

Reid also began trying to play hardball with Boehner, telling him that they wouldn’t compromise on the abortion issue and there were no more cuts to be made, according to a senior Democratic leadership aide.

On Friday, Senate Minority Leader Mitch McConnell (R-Ky.) — who largely stayed out of the talks — called Reid and asked for a final favor for Boehner.

Reid said no. But he later gave in, in exchange for Boehner’s decision to drop the Planned Parenthood demand. Reid and Obama said they would allow for an additional $500 million in spending cuts.

Across town, OMB was preparing three memos to be sent to federal workers. One announced a shutdown. Another said the government would stay open. The third, anticipating a deal that came after midnight, would allow for a continuation of a few hours.

The Capitol’s own tourist-jammed hallways emptied out, leaving just milling reporters and scurrying lawmakers. After 10 p.m., with less than two hours remaining, Boehner called his fractious group of Republicans in for a meeting.

He told them there was still no final deal. But then he began to outline, in a calm voice, what a potential deal might be.

“That was the first time in weeks that they’ve told us specifics,” said Rep. Steve Pearce (R-N.M.), one of the most conservative members of the freshman class. Pearce knew what it meant: “You never reveal things in negotiations until it’s done.”

In fact, as they talked in the basement, aides to Boehner, Obama and Reid were shaking hands in the Speaker’s ornate office two floors up.

They had finally reached a deal: Boehner dropped his demand to take Planned Parenthood’s funds. In return, he got $78 billion in spending cuts — the $38 billion in cuts from last week’s deal, plus $40 billion in increases to agency budgets proposed by Obama that were never agreed to. And he got the D.C. abortion provision Obama had offered the night before.

Later, D.C. Mayor Vincent C. Gray expressed outrage.

“The District of Columbia’s right to govern itself has, once again, been sacrificed on the altar of political expediency,” Gray said in a statement afterward. “This is ludicrous. . . .Hypocrisy is alive and well in the United States Congress.”

Calls went out. In the basement, Boehner was handed a slip of paper.

“There’s a deal!” he said. The room cheered.

Then, they had to hustle out to vote. By arriving at his deal with only minutes remaining before a shutdown, Boehner had allowed his rebellious conservatives little time to react.

But there may be more rebellions to come.

When House members rushed in to vote for a short-term budget measure — designed to allow a few days for the final deal to be approved next week — 28 Republicans voted no.

It was another sign: They were happy that Boehner had pushed the Democrats to the brink. But some conservatives thought that maybe they could have pushed Boehner even further.

“I voted against it. But I also appreciated the fact that it got solved,” Pearce said. He said his “no” vote was a message for Boehner, “to let the speaker know that, ‘You can take a little tougher position. We’re going to be behind you.’ ”

Obama’s moment

On Saturday, President Obama turned up at the Lincoln Memorial to shake hands with tourists — and remind everybody of the deal that was made on his watch.

“I just wanted to say, real quick, that because Congress was able to settle its differences, that’s why this place is open today and everybody’s able to enjoy their visit,” Obama said, according to reports. “And that’s the kind of future cooperation I hope we have going forward.”

At OMB, officials chucked the memo they had prepared to announce a shutdown. Instead, they sent out the one that announced the government would not stop at all.

“Thank you for your cooperation and support throughout this process,” it said.

Which might be as close to an apology as they’re going to get.

Staff writers Ed O’Keefe, Philip Rucker and Felicia Sonmez contributed to this report.