A dramatic eleventh-hour deal slashing spending 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 ê38.5 billion dollars 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. And I would not have made these cuts in better circumstances," the president said.
"But beginning to live within our means is the only way to protect those investments that will help America compete for new jobs," he said, after a long day of suspenseful negotiating averted a deep political crisis.
House Speaker John Boehner earlier 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).
"It's been a gruelling 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 put America's slow recovery from the worst economic crisis since the 1930s Great Depression at risk.
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 like the war in Afghanistan and border services would have gone on as normal.
McConnell wasted little time signalling that Republicans would do battle with Obama on his request to raise Washington's ability to borrow -- and 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.