A bill that keeps the government funded until 17 November- but includes no new aid for Ukraine - was approved in the Senate by 88 votes to nine.
President Joe Biden signed it into law minutes before the midnight deadline.
The proposal was put forward by Republican House Speaker Kevin McCarthy, as he fought off a rebellion by hard-liners in his own party.
A shutdown, which would place tens of thousands of federal employees on furlough without pay and suspend various government services, was slated to begin at 00:01 ET (04:01 GMT) on Sunday.
But in a dramatic turnaround on Saturday afternoon, House Republicans scrambled to pass a temporary funding measure that would keep the government open for until mid-November and make no major concessions on spending levels.
It was backed by more Democrats than Republicans, with as many as 90 Republicans voting against it.
The move was a blow to a small group of right-wing Republicans who have held up negotiations in the chamber with unyielding demands for spending cuts.
However, with a majority of lawmakers keen to avert a shutdown, one of the faction's key demands - no more US funding for Ukraine's defence against its invasion by Russia - is reflected in the bill.
In a statement released shortly after the Senate vote, President Joe Biden said "extreme House Republicans" had sought to create a "manufactured crisis", and urged Speaker McCarthy to allow a further funding deal for Ukraine to pass without delay.
He said: "We cannot under any circumstances allow American support for Ukraine to be interrupted."

Speaking after the deal passed, Democratic Senate majority leader Chuck Schumer said "Americans can breathe a sigh of relief" and that "extreme, nasty and harmful" budget cuts some Republicans had pushed for had been avoided.
But he stressed the agreement was not the "final destination", assuring Kyiv that a further funding package for Ukraine had not been abandoned, adding: "We will not stop fighting for more support for Ukraine."