A $1.1 trillion spending bill is on its way to U.S. President Barack Obama for his signature.

The Senate voted 56-40 on Saturday for the long-term funding bill, the main item left on Congress' year-end agenda. The measure provides money for nearly the entire government through the Sept. 30 end of the current budget year.

Obama has said he will sign the bill. He already signed a short-term spending bill on Saturday that will keep the federal government operating through Wednesday, easing concerns of a shutdown during the holiday season.

Senators approved the temporary measure Saturday afternoon with only hours to spare before an earlier such measure was set to expire

Congress cleared the controversial spending bill late Saturday night after a day of Senate intrigue capped by a failed, largely symbolic Republican challenge to the administration's new immigration policy.

It was Texas Republican Senator Ted Cruz who pushed the Senate to cast its first vote on the administration's policy of suspending the threat of deportation for an estimated four million immigrants living in the country illegally. He lost his attempt Saturday night, 74-22, although Republican leaders have vowed to bring the issue back after the party takes control of the Senate in January.

APTOPIX Republicans Healthcare

Republican Texas Senator Ted Cruz suggested Senate Minority Leader Mitch McConnell, left, and House Speaker John Boehner should not be trusted to keep their pledge to challenge President Barack Obama's immigration plan when Republicans gain control of both houses of Congress in January. (J. Scott Applewhite/Associated Press)

"If you believe President Obama's amnesty is unconstitutional, vote yes. If you believe President Obama's amnesty is consistent with the Constitution, vote no," Cruz said.

Senate Majority Leader Harry Reid rebutted instantly, saying Cruz was "wrong, wrong, wrong on several counts," and even Republicans who oppose Obama's policy abandoned the Texan.

The Senate Republican leader, Mitch McConnell, made no public comment on Cruz's tactic, even thought the Texan  suggested Friday night that McConnell and House Speaker John Boehner should not be entirely trusted to keep their pledge to challenge Obama's immigration policy in January.

The Senate passed the bill on a day Democrats launched a drive to confirm two dozen of Obama's stalled nominees to the federal bench and administration posts, before their majority expires at year's end.

Several Republicans blamed Cruz for giving the outgoing majority party an opportunity to seek approval for presidential appointees, including some that are long-stalled. As the day wore on, senators were forced to spend hour after hour on the Senate floor to cast their votes.

The spending bill, which cleared the House on Thursday, exposed fissures within both political parties in both houses. It faced opposition from Democratic liberals upset about the repeal of a banking regulation and Republican conservatives unhappy that it failed to challenge Obama's immigration moves.

Bipartisan agreement on pensions

A pension provision included in the bill was a bipartisan agreement that opens the door for the first time to benefit cuts for current retirees covered by multi-employer funds in shaky financial condition.

Supporters said it would protect retirement income to the maximum extent possible without also endangering the solvency of the government fund that guarantees multi-employer plans. Critics said it posed a threat to the pension recipients, and that it could also become a precedent for other pensioners.

Many Democrats, including Obama, recognized that if the current spending bill fails, Republicans would pass an even more objectionable one when they take full control of Congress next month. Obama called the bill a classic compromise produced by "the divided government that the American people voted for."