There was barely an hour left before the midnight padlocking of government doors. In a Capitol basement meeting room, House Speaker John Boehner was telling exhausted fellow Republicans that a deal to avert a shutdown was nearly finished when an aide alerted him that staff had completed the final details and the agreement was complete.
"He said we don't have the Senate and we don't have the White House, and it's a good day's work," said Rep. Jack Kingston, R-Ga., who was in the closed-door session and later described the scene.
And with that, Republicans clapped: "Not euphoria," Kingston said, reflecting fatigue and the realization of a long year of intense budget battling lay ahead. But for now, a week of top-level White House meetings, round-the-clock bargaining by staff and lots of emotional hills and valleys had produced a bipartisan accord to trim $38.5 billion in spending over this fiscal year's remaining six months and head off a federal shutdown that both parties feared could hurt their standing with voters.
To get there, the two sides followed a twisting path, according to accounts offered Friday and Saturday by Obama administration, House GOP and Senate Democratic aides who spoke on condition of anonymity to describe confidential talks.
The path toward a spending collision began in February, when the new GOP majority pushed a bill through the House over Democratic opposition, cutting this year's spending by $61 billion. The measure included dozens of provisions curbing enforcement of environmental laws, restricting federal aid for family planning and other limitations.
That bill was rejected by the Democratic-run Senate.
With no permanent legislation in place financing federal agencies for the remaining six months of the government's fiscal year, Congress started enacting bills cutting spending and providing enough money for the government to function for just weeks at a time.
With the most recent stopgap measure expiring April 8, lawmakers worried about a public perception that they couldn't do their most basic work began looking for a way to end their impasse.
Two weeks ago, bipartisan talks started in earnest, with bargainers initially focusing on finding $33 billion in cuts. Shy of a deal and with a potential government shutdown looming, Obama invited leaders of both parties to a White House bargaining session last Tuesday.
It was clear that that session had not gone well when Boehner issued a written statement afterward saying, "We can still avoid a shutdown, but Democrats are going to need to get serious about cutting spending _ and soon." Reid fired back, "I hope the Republicans do what the country needs, not what they believe the tea party wants," a reference to the influential conservatives who helped the GOP gain power in last November's elections.
Those comments set the tone for an acrimonious week.
Democrats repeatedly accused Republicans of seeking harmful spending cuts, trying to use the bill to restrict programs for women's health and constantly making new demands every time a deal seemed near. Republicans said Democrats were not serious about controlling federal spending, and accused them of holding the military hostage when the Senate refused to consider a spending-cut bill that would have financed the Pentagon for the rest of the year.
Another meeting followed Wednesday night in the White House dining room, where at one point staff was asked to leave the room, according to a senior Senate Democratic leadership aide. Boehner wasn't proposing a specific figure for cuts, that aide said, and was pressing for the inclusion of policy restrictions that Republicans wanted.
Also at that meeting, Boehner said he would need deeper cuts than Democrats were offering, according to a House Republican aide also speaking on background. The Democratic aide said that when that meeting ended, his side's hopes for a deal had dimmed to a 1 in 5 chance of success.
Staff worked late into the night, but there was no breakthrough. Those involved included Rob Nabors, the White House legislative affairs director; Boehner chief of staff Barry Jackson; and David Krone, Reid's chief of staff.
With the clock ticking down, two more White House bargaining sessions were held Thursday among the president, Boehner and Reid.
In one of the White House meetings, a light moment occurred when the negotiators began focusing on the dozens of policy restrictions that Republicans wanted to include.
According to White House aides, Nabors had an assistant make photocopies of the long list of provisions, which ended up taking time. Boehner joked about the White House needing faster copying machines, and Obama said the copies were being mimeographed, an ancient copying technology.
A key point came Thursday night, according to the Senate Democratic staffer and White House aides.
The two sides were moving closer to agreement on the amount of spending cuts but Republicans were insisting on including curbs on federal funds for family planning programs _ a demand that Democrats were just as adamantly opposing.
It was in those conversations, the Democratic aide said, that Obama and Reid said Democrats would not agree to the family planning restrictions, with the president himself saying it would not be included in any final deal. At one point, according to White House aides, Vice President Joe Biden flashed anger over the GOP's insistence on family planning restrictions.
Instead, Democrats suggested to GOP aides that when the Senate debates the spending legislation, it would vote on the restrictions Republicans want on federal aid for family planning _ a suggestion that GOP staff showed some interest in.
On Friday, that formula ended up being the way that issue was resolved _ even though the Senate is considered sure to vote it down.
But the two sides still hadn't reached a final spending cut figure.
After Thursday evening's White House meeting, administration and Senate Democratic aides met with House GOP staffers at the Capitol until well after midnight, the Senate Democatic aide said.
At 4:30 a.m., the White House proposed $38 billion in cuts, and Republicans made a $39 billion counter-offer shortly before noon, the Democratic aide said. Hours were spent fine-tuning the final number to $38.5 billion and working out exactly where the cuts would come from. White House aides, who spoke on condition of anonymity, said that besides being focused on the size of the cuts, they wanted to avoid slashing education, health and other administration priorities.
Helping the process, White House aides said, was a call Obama made that morning to Boehner, complaining that GOP aides were still discussing deeper cuts than the White House wanted.
When they'd finally finished their negotiation Friday night in the Capitol, Jackson, Krone and Nabors shook hands. Jackson tried telephoning Boehner, who was addressing GOP lawmakers, but the speaker's cell phone was off, according to House GOP aides.
So Jackson walked down to the basement conference room, opened the door and nodded to the speaker.
According to the aides, Boehner turned to his fellow Republicans and said, "We have a deal."
Associated Press writers Ben Feller and Andrew Taylor contributed to this report.