The US House of Representatives narrowly passed a $1.1 trillion (€887 billion) budget just hours before the government was due to shut down at midnight overcoming last-minute in-fighting among both Democrats and Republicans.
The Republican bill passed by 219 votes to 206 after President Barack Obama called on fellow Democrats, who were split on proposals tied to the budget, to support the measure.
Fifty-seven Democrats voted for the bill in one of the last acts of the 113th Congress, one of the most politically divided and least productive in modern times, ahead of Republicans taking control of the House and Senate in January.
The spending bill, which funds most of the government until September 2015 though on an emergency basis in some areas, excludes funding for the Department of Homeland Security beyond February.
This gives Republicans the opportunity to launch another attack on Mr Obama’s executive actions on immigration to shield up to five million illegal immigrants from deportation from next spring.
Liberal House Democrats were most alarmed by the bill’s rollback of the 2010 Dodd-Frank financial regulations, which they argued would expose taxpayers to risks arising from complex financial “swap” trading by Wall Street banks.
Nancy Pelosi, the minority leader in the House, broke with the Obama administration in a rare moment of in-party fighting among Democrats over the measure, saying that said she was "enormously disappointed" with the president's position over the relaxation of the post-crisis banking rules and weakening of consumer protection.
"This is ransom, this is blackmail. You don't get a bill unless Wall Street gets its taxpayer coverage. It's really so sad," said the California Democrat in a stinging speech on the House floor.
The White House and Republican leaders in the House formed an unusual alliance in a bid to win enough votes to pass the bill and avoid another government shutdown, similar to the October 2013 closure.
The president and vice president, Joe Biden, lobbied liberal House Democrats in a flurry of phone calls urging support for the bill. Mr Obama dispatched White House chief of staff Denis McDonough to the Capitol to win over reluctant Democrats in private meetings.
On the Republican side, House Speaker John Boehner rallied support among his party amid concerns among conservatives who felt the bill didn't go far enough to stop Mr Obama's immigration plans.
In the end 67 Republicans defected but the 57 Democratic votes were enough to help pass the bill.
"In a world of alternatives, I have concluded that it's better for us to pass this… than it is to defeat it," said House minority whip Steny Hoyer, the second highest-ranking Democrat in the lower chamber.
The legislation must pass the Senate but a two-day extension of existing government funding will create time for senators to vote on the budget today and for the budget to be signed into law by the president.
The bill became better known in Capitol Hill circles and the political media as the “Cromnibus” - a combination of a “continuing resolution,” the congressional term for a short-term budget, and an “omnibus” spending bill covering a variety of measures.
Among the 1,600-page bill were concessions to Republicans, including an increase in the amount a person can donate to a political party, from $32,000 to $324,000, and blocks to certain Environmental Protection Agency regulations along with cuts in its budget.
The bill also blocks the District of Columbia from using its own funds to establish a regulatory system legalising marijuana. Voters in the District voted for the legalisation of marijuana in last month’s elections but the city relies on federal funds approved by Congress.