The Senate's 56-40 vote sends the measure to President Barack Obama, who is expected to sign it into law before federal spending authority expires at midnight on Wednesday.
Passage of the 1,603-page bill was a long, tough struggle in the Senate and the House of Representatives marked by bitter disputes over changes to banking regulations and Obama's recent executive order on immigration.
Liberal Democrats, led by Senator Elizabeth Warren, objected to a weakening of the Dodd-Frank financial reform law, while conservative Republicans, led by Tea Party firebrand Ted Cruz, tried to sink it for failing to stop Obama's order.
Cruz's tactics to delay the bill created an opening for Democrats in a rare Saturday session to push through dozens of Obama's nominations opposed by Republicans, from judges to energy regulators. His party colleagues were angered.
"I think most Republicans feel like that Christmas came early for Democrats," said Republican Senator Lindsey Graham. "At the end of the day, they got nominees we previously successfully blocked and we got nothing."
The legislation funds most government agencies through September 2015. The Department of Homeland Security will be treated differently, getting a funding extension only through Feb. 27, by which time Republicans will control both chambers of Congress.
Republicans insisted on the shorter leash for DHS so that they can try to deny the agency any funds for implementing Obama's recent order easing deportations for millions of undocumented immigrants.
The Senate vote closed the latest chapter in a four-year-long battle between Democrats and Republicans over U.S. fiscal policy during an era of large budget deficits.
These battles are expected to resume next year but with a twist: Republicans, having won big gains in the Nov. 4 congressional elections, take control of the Senate from Democrats with a 54-46 majority and will enjoy a larger majority in the House.
Nonetheless, Republicans will still need cooperation from Democrats in the Senate, where 60 out of 100 votes are needed to advance most major bills.
TEXAN STRIKES AGAIN
Cruz, a potential 2016 presidential candidate, had delayed the spending bill over demands for an up-or-down vote denying funds for Obama's immigration plans.
It was reminiscent of his role as the ringleader of the October 2013 government shutdown that lasted 16 days, when he insisted on gutting Obama's healthcare law.
As in 2013, this latest budget fight ended with Cruz failing to score a victory and Democrats bashing Republicans for again raising the specter of a government shutdown.
A revolt by Warren and House Democratic leader Nancy Pelosi, a longtime Obama ally, over a provision to ease Wall Street banking regulations fed tensions on Capitol Hill all week.
The House vote was delayed for seven hours on Thursday after Democrats balked at the provision to kill new restrictions on derivatives trading by large banks, weakening Dodd-Frank, one of Obama's early legislative achievements passed in response to the 2008 financial crisis, triggered partly by complex mortgage derivatives.
Banks argue the regulations would have been ineffective and costly.
The provision was partly responsible for 21 "no" votes from Senate Democrats, which outnumbered 18 Republicans and one independent opposing it.
The spending bill provides for a slight increase in Pentagon war funding, which would total $64 billion for this fiscal year. Some of the money is for combating Islamic State in Iraq and Syria.
Other high-priority items include nearly $5.5 billion to help contain the Ebola virus, including Defense Department efforts in West Africa.
Internal Revenue Service spending would be cut and Republicans also inserted initiatives ranging from prohibiting funding for the Environmental Protection Agency to regulate lead content in ammunition and fishing tackle, to stopping the transfer or release of Guantanamo detainees into the United States.