© The Associated PressJohn Boehner, left, and Barack Obama each announced a shutdown had been avoided.
Racing the clock, in a long day of trading offers, the White House and Speaker John Boehner reached agreement Friday night on a budget framework that would cap 2011 appropriations just under $1.050 trillion while cutting domestic and foreign aid by more than $40 billion from the rate of spending at the beginning of this Congress.

The deal - which was only sealed after Boehner presented the outline to a closed door Republican Conference - averts what would have been an unprecedented wartime shutdown of the government that had become a growing embarrassment for himself and President Barack Obama.

Down to the end, Boehner was still pressing for a lower top line when Obama called him in the early evening. Both men later cast the agreement as the best available, but the grueling, often distrustful process testified to how tough this legislative year will be and the immense pressure on the speaker from the right.

The administration largely succeeded in blocking the most controversial policy riders impacting the environment and abortion-rights. But the cut is one of the single largest in history, and a preview of what lies ahead when Republicans move their 2012 budget plan next week and fight with Obama over raising the debt ceiling in May and June.

"Like any worthwhile compromise, both sides had to make tough decisions and give ground on issues that were important to them," Obama said. "And I certainly did that."

"We didn't do it at this late hour for drama," said Senate Majority Leader Harry Reid (D-Nev.), the third major player in the talks. "We did it because it has been hard to arrive at this point."

White House Budget Director Jack Lew and the president's chief legislative liaison Rob Nabors spent much the day holed up in the Senate leadership offices, fielding what became an almost rapid fire succession of offers and counter offers from the House.

"I think it will be resolved," Senate Appropriations Committee Chairman Daniel Inouye (D-Hawaii) told POLITICO late in the afternoon, but Reid's own staff were still nervous enough to say 50-50 by evening.

With a deal in hand and no time to spare, the Senate quickly adopted a one week stop gap bill to keep the government operating and buy time for processing the final package.

Just minutes after midnight, the House followed suit. And Appropriations Committee clerks, who had been waiting at their desks, were to immediately begin writing the budget measure, which covers the last six months of this fiscal year ending Sept. 30.

Friday night's agreement comes almost a full two months after the House first started the fight Feb 19 with a bill cutting $61.3 billion from spending levels at the beginning of this year and more than $100 billion from Obama's initial budget request for 2011.

By comparison, the measure now would cut $38 billion from this year's spending and $78 billion from Obama's budget - more than halfway toward the GOP in each case. But factoring in what will be a more than $4 billion increase for the Pentagon, the true cut for domestic and foreign aid programs is closer to $42 billion.