Updated

Congressional leaders, with barely an hour to go before a federal government, announced late Friday night they had reached a deal to fund the government through the end of the fiscal year.

The deal includes $38.5 billion in spending cuts while leaving the more contentious policy matters, such as blocking funding for Planned Parenthood, for a later debate.

The Senate passed a short-term spending measure Friday night to buy lawmakers the time needed to prepare and pass the final budget bill next week. The House passed the measure early Saturday, which will be signed by President Obama when he receives it, according to senior administration officials.

"This agreement between Democrats and Republicans on behalf of all Americans is a budget that invests in our future while making the largest spending cut in our history," Obama said in a short speech to the nation after the deal had been announced. "Today Americans of different beliefs came together again."

Shortly after midnight, White House budget director Jacob Lew issued a memo instructing the government's departments and agencies to continue their normal operations.

More On This...

Of the $38.5 billion in spending cuts to Obama's original 2011 budget proposal, the short-term stopgap measure contains the first $2 billion and the final budget bill will cut the other $36.5 billion.

Boehner said the agreement came after "a lot of discussion and a long fight," and he won an ovation from his rank and file.

"We fought to keep government spending down because it really will be a jobs creator for our country," Boehner said.

On Friday, senior administration officials said Obama made it clear to his staff that he wanted them to stay out of the limelight and let the legislative process work. He urged them to avoid making comments that would hamper a potential deal.

It was a remarkable end to a roller-coaster week of negotiations, in which the government several times seemed headed for a shutdown because the two sides couldn't agree on a full-year budget.

Obama has already signed two temporary spending bills, which included a total of $10 billion in spending cuts, but he said this week he wasn't interested in any more short-term fixes.

As late as hours before the agreement, a government shutdown seemed quite possible -- if not inevitable -- as both sides couldn't even agree, at least in public, on what was holding up a deal.

Democrats said Republicans were pushing for social policy measure, while Republicans said the Democrats hadn't agreed to enough spending cuts.

But in the end, neither side wanted a shutdown that would risk the economic recovery and their political future.

Senate Majority Leader Harry Reid called the agreement "historic."

"Both sides have made tough choices, but tough choices is what this job is all about," Reid said.

Obama called Boehner and Reid after the announcement of the budget resolution to thank them for their work.

The government's current fiscal year began back in October, but Democrats last year, facing stiff opposition from Republicans, put off a vote on a full-year budget as both parties geared up for the midterm elections. The standoff began in earnest several weeks ago, when the new

Republican majority in the House passed legislation that would fund the government for the rest of the year, but with $61 billion in cuts and numerous curbs on the government that Democrats objected to.

In the weeks since, the two sides have alternately negotiated on a budget for the rest of the year and taken time out to pass interim measures to buy themselves more time.

Republicans originally wanted to ban federal funds for Planned Parenthood, a health care services provider that is also the nation's largest provider of abortions.

Federal funds may not be used to pay for abortions except in strictly regulated cases, but supporters of the ban said cutting off government funds for the organization -- currently about $330 million a year -- would make it harder for it to use its own money for the same purpose.

Democrats rejected the proposal in private talks. Officials in both parties said Republicans returned earlier in the week with a proposal to distribute federal funds for family planning and related health services to the states, rather than directly to Planned Parenthood and other organizations.

Democrats said they rejected that proposal as well, and Obama had vowed to veto a bill that the House passed Tuesday to fund then refused to agree to allow a separate Senate vote on the issue as part of debate over any compromise bill.

The Associated Press contributed to this report.