With under 10 hours to go before the US government is due to shut down, the House of Representatives has reached agreement on short-term funding.
The bill, which keeps the government funded until mid-November but includes no new US aid for Ukraine, was approved by a vote of 335 to 91.
The measure still requires support in the upper congressional chamber, the Senate, but is expected to pass.
Once signed into law, it will avert a disruption of federal services.
A shutdown – that 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.
Shutdowns take place when both chambers of Congress are unable to agree on the roughly 30% of federal spending it must approve before the start of each fiscal year on 1 October.
Under divided control of Washington, with Republicans holding a slim majority in the House and Democrats holding the Senate by a single seat, any funding measure needs buy-in from both parties.
But efforts to pass spending bills in the House have been thwarted in recent weeks by a rebel faction of right-wing lawmakers, who have demanded significant cuts, including no more funding for Ukraine’s defence against its invasion by Russia.
Numerous efforts to pass both long and short-term spending bills had failed in the House over the past few days.
In a dramatic turnaround on Saturday afternoon, House Republicans scrambled to pass a temporary funding measure to keep the government open for 45 more days, which also makes no major concessions on spending levels.
It was backed by more Democrats than Republicans in the House, with as many as 90 Republicans voting against it.
Relying on Democratic votes to pass the bill was a move House Speaker Kevin McCarthy had, up until the last minute, been extremely reluctant to make – given this would anger the most conservative members of his party.
But Democrats did not get everything they wanted. In order to avoid a shutdown, they had to abandon their hopes of providing further military aid to Ukraine.
They – and Republicans who also support more Ukraine money – will keep pressing for more funding, but Biden administration officials warn that in the short term there could be disruption to the Ukrainian war effort.
“We fully expect Speaker McCarthy – who has stated his support for funding to support Ukraine in its fight against Russia’s illegal and unjustified war of aggression – will bring a separate bill to the floor shortly,” a White House official told the BBC’s US partner CBS News.
Lawmakers in the Senate are expected to quickly take up the bill and attempt to pass it on Saturday evening, so it can be rushed to President Joe Biden’s desk for his signature.
As the House scrambled for votes on Saturday, Republicans in the Senate backed away from a bipartisan funding measure that had been making its way through that chamber, which included $6bn in aid to Ukraine.
Assuming the Senate follows the House’s lead and quickly approves its short-term bill, the government will stay open – at least for now.
But this drama is likely to be repeated in 45 days, however, as fundamental disagreements over government spending levels and policies between Republicans and Democrats, and among Republicans themselves, have not been resolved.
In the meantime, Florida Congressman Matt Gaetz and hard-line conservatives in the House have a decision to make.
Their procedural roadblocks this month were bypassed by Mr McCarthy in his decision to rely on Democratic votes to pass the short-term bill.
That was supposedly a red line that, if crossed, would prompt a right-wing rebellion in the House and an attempt to remove Mr McCarthy from his leadership position.
The days ahead will reveal whether Mr Gaetz and company were serious about their threat – or just bluffing.