WASHINGTON — After moments of high drama, dry process and acrimony, the Senate passed a sweeping $1.1 trillion spending package Saturday night, abruptly ending several days of chaotic legislative maneuvers and clearing the bill for President Obama to sign.

The legislation, which will fund most of the government through the fiscal year that ends in September, passed in a bipartisan vote, 56 to 40, after a turbulent process — a fitting coda for a governing body that has often failed to govern.

The vote concluded a long day of brinkmanship, spurred by a legislative challenge to Mr. Obama’s executive action on immigration by Senator Ted Cruz, Republican of Texas, who helped force the Senate into a weekend session. By the end of the day, Mr. Cruz found himself isolated even from members of his own party.

“I don’t see what we’re achieving here,” Senator Jeff Flake, Republican of Arizona, said of Mr. Cruz’s strategy.