A dramatic 11th-hour deal slashing spending has staved off a US government shutdown, ending a rancorous budget row between President Barack Obama and his newly empowered Republican foes.
Party leaders clinched the agreement, including some US$38.5 billion of extra spending cuts, after intense bargaining, barely an hour before the federal government effectively ran out of money at midnight Friday.
The showdown was just the first bruising engagement in a string of likely clashes between Obama and Republicans boosted by a new crop of conservative Tea Party lawmakers, as the president fires up his 2012 reelection bid.
Obama boasted in remarks at the White House that cooperation born of difficult compromises had yielded "the biggest annual spending cut in history" at a time when Washington faced a projected annual shortfall of $1.65 trillion.
"Some of the cuts we agreed to will be painful. Programs people rely on will be cut back. Needed infrastructure projects will be delayed," the president said.
He continued to sell the deal to the public on Saturday, saying in his weekly radio address that "beginning to live within our means is the only way to protect the investments that will help America compete for new jobs."
House Speaker John Boehner told his restive Republican caucus behind closed doors he had sealed an agreement with the White House to fund the government for the rest of the fiscal year ending October 1.
"This has been a lot of discussion and a long fight. But we fought to keep government spending down because it really will, in fact, help create a better environment for job creators in our country," he told reporters afterwards.
Lawmakers in both chambers raced to approve a stopgap funding measure before midnight to give negotiators until Thursday to finalize the overall deal.
The Senate passed it by voice vote, the House by a 348-70 margin at 12:39 am (0439 GMT) Saturday.
"It's been a grueling process. We didn't do it at this late hour for drama. We did it because it has been hard to arrive at this point," said Democratic Senate Majority Leader Harry Reid, his party's lead negotiator.
Anticipating a possible insurrection, Boehner told Republicans "this is the best deal we could get out of them," according to two officials who attended the emotional gathering.
Republican Representative Marsha Blackburn wept about the possible impact of spending cuts on a military base dear to her district, a witness said. Another came from a formal event still in black tie. Another wore a ball gown.
The agreement came after a long day in which Republican leaders parried every question with a "no deal" up to three hours before the deadline, despite telephone discussions between Obama and Boehner.
Participants nervously alluded to 1995, when the US government last plunged into a shutdown caused by a funding row, and Bill Clinton outmaneuvered his Republican foes and rescued a sagging presidency.
"We had an opportunity tonight to decide whether we wanted to repeat history or make history. We decided to make history," said Republican Senate Minority Leader Mitch McConnell.
Obama had warned that a prolonged government shutdown could jeopardize America's slow recovery from the worst economic crisis since the 1930s Great Depression.
A shutdown would have seen around 800,000 federal employees temporarily laid off, paychecks for frontline combat soldiers delayed and national parks and monuments closed.
But operations vital to national security such as the war in Afghanistan and border services would have gone on as normal.
McConnell wasted little time signaling that Republicans would do battle with Obama on his request to raise Washington's ability to borrow -- an issue that has inflamed the Tea Party.
"Senate Republicans and House Republicans -- and I hope many Democrats as well -- are going to say 'Mr President, in order to raise the debt ceiling we need to do something significant about the debt,'" he said.
The overall spending accord removed what Democrats had described as the biggest obstacle to a deal: A Republican-crafted measure stripping federal funding from the Planned Parenthood clinics that provide abortions.
Obama canceled a planned trip to Indiana on Friday to stay in Washington and see the final push to the end. He also called off a weekend away with his family in the historic Virginia city of Williamsburg.