Senate passage set the stage for a final showdown in the House, where a vote was expected later Tuesday or perhaps Wednesday on the measure, which also raises tax rates on wealthy Americans.
Even by the recent dysfunctional standards of government-by-gridlock, the activity at both ends of historic Pennsylvania Avenue was remarkable as the administration and lawmakers spent the final hours of 2012 haggling over long-festering differences.
"It shouldn't have taken this long to come to an agreement, and this shouldn't be the model for how we do things around here," said Senate Republican leader Mitch McConnell, who negotiated the agreement with Vice-President Joe Biden.
Shortly after the Senate vote, President Barack Obama said, "While neither Democrats nor Republicans got everything they wanted, this agreement is the right thing to do for our country and the House should pass it without delay."
Under the deal, taxes would remain steady for the middle class and rise at incomes over $400,000 for individuals and $450,000 for couples — levels higher than Obama had campaigned for in his successful drive for a second term in office.
Spending cuts totalling $24 billion over two months aimed at the Pentagon and domestic programs would be deferred. That would allow the White House and lawmakers time to regroup before plunging very quickly into a new round of budget brinkmanship certain to revolve around Republican calls to rein in the cost of Medicare and other government benefit programs.
Officials also decided at the last minute to use the measure to prevent a $900 pay raise for lawmakers due to take effect this spring.
"One thing we can count on with respect to this Congress is that if there's even one second left before you have to do what you're supposed to do, they will use that last second," the president said in a mid-afternoon status update on the talks. Yet when the roll was called nearly 12 hours later, only six Republicans and two Democrats opposed the measure.
As darkness fell on the last day of the year, Obama, Biden and their aides were at work in the White House, and lights burned in the House and Senate. Democrats complained that Obama had given away too much in agreeing to limit tax increases to incomes over $450,000, far above the $250,000 level he campaigned on. Yet some Republicans recoiled at the prospect of raising taxes at all.
Democratic senators said they expected a post-midnight vote on the measure. They spoke after a closed-door session with Vice-President Joseph Biden, who brokered the deal with Senate Republican leader Mitch McConnell.
"The argument is that this is the best that can be done on a bipartisan basis," said Sen. Dianne Feinstein, D-Calif., when asked about the case the vice-president had delivered behind closed doors.
Passage would send the measure to the House, where Speaker John Boehner, R-Ohio, refrained from endorsing a package as yet unseen by his famously rebellious rank-and-file. He said the House would not vote on any Senate-passed measure "until House members — and the American people — have been able to review" it.
Numerous GOP officials said McConnell and his aides had kept the speaker's office informed about the progress of the talks.
The House Democratic leader, Rep. Nancy Pelosi of California, issued a statement saying that when legislation clears the Senate, "I will present it to the House Democratic caucus."
Without legislation, economists in and out of government warned of a possible recession if the economy were allowed to fall over a fiscal cliff of tax increases and spending cuts.
And while the nominal deadline for action passed at midnight, Obama's signature on legislation by the time a new Congress takes office at noon on Jan. 3, 2013 — the likely timetable — would eliminate or minimize any inconvenience for taxpayers.
A late dispute over the estate tax produced allegations of bad faith from all sides.
After hours of haggling, Biden headed for the Capitol to brief the Democratic rank and file.
Earlier, McConnell had agreed with Obama that an overall deal was near. In remarks on the Senate floor, he suggested Congress move quickly to pass tax legislation and "continue to work on finding smarter ways to cut spending" next year.
The White House and Democrats initially declined the offer, preferring to prevent the cuts from kicking in at the Pentagon and domestic agencies alike. A two-month compromise resulted.
Officials in both parties said the agreement would prevent tax increases at incomes below $400,000 for individuals and $450,000 for couples.
At higher levels, the rate would rise to a maximum of 39.6 per cent from the current 35 per cent. Capital gains and dividends in excess of those amounts would be taxed at 20 per cent, up from 15 per cent.
The deal also would also raise taxes on the portion of estates exceeding $5 million to 40 per cent. At the insistence of Republicans, the $5 million threshold would rise each year with inflation.
Much or all of the revenue to be raised through higher taxes on the wealthy would help hold down the amount paid to the Internal Revenue Service by the middle class.
In addition to preventing higher rates for most, the agreement would retain existing breaks for families with children, for low-earning taxpayers and for those with a child in college. Also, the two sides agreed to prevent the alternative minimum tax from expanding to affect an estimated 28 million households for the first time in 2013, with an average increase of more than $3,000. The law originally was designed to make sure millionaires did not escape taxes, but inflation has gradually exposed more and more households with lower earnings to its impact.
The legislation leaves untouched a scheduled 2 percentage point increase in the payroll tax, ending a temporary reduction enacted two years ago to help revive the economy.
Officials said the White House had succeeded in gaining a one-year extension of long-term unemployment benefits about to expire on an estimated two million jobless.
The legislation would delay for one year a 27 per cent cut in fees for doctors who treat Medicare patients.
Also included is a provision to prevent a threatened spike in milk prices after the first of the year.
Even as time was running out, partisan agendas were evident.
Obama used his appearance not only to chastise Congress, but also to lay down a marker for the next round of negotiations early in 2013, when Republicans intend to seek spending cuts in exchange for letting the Treasury to borrow above the current debt limit of $16.4 trillion.
"Now, if Republicans think that I will finish the job of deficit reduction through spending cuts alone — and you hear that sometimes coming from them ... then they've got another think coming. ... That's not how it's going to work at least as long as I'm president," he said.
"And I'm going to be president for the next four years, I think," he added.
Obama's remarks irritated some Republicans.
Sen. John McCain of Arizona they would "clearly antagonize members of the House."
Associated Press writers Julie Pace, Andrew Taylor, Alan Fram and Ben Feller contributed to this report.
Also on HuffPost