The US government has avoided a federal shutdown after both House and Senate agreed on a short-term funding deal.
A bill ensuring funding until 17 November received overwhelming support, and was signed into law by President Joe Biden minutes before a deadline.
However, it excludes any new aid for Ukraine in a blow for Democrats, for whom this was a key demand.
Republican House Speaker Kevin McCarthy submitted the bill in defiance of hard-liners in his own party.
A government 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, Mr McCarthy decided to put to a vote the temporary funding measure that would keep the government open.
The measure contains funding for natural disasters but makes no major concessions on spending levels – a key demand of the Republicans controlling the lower house.
A majority of lawmakers were keen to avert a shutdown, and the bill was backed by more Democrats than Republicans, with as many as 90 House 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 and no new aid for Ukraine.
And with the House adjourning immediately after the vote, the Senate which had agreed its own bill that included aid for Ukraine was left with no choice but to pick up the House legislation. Only nine senators voted against – all Republican.
Mr McCarthy admitted that the last-minute agreement was not the route he wanted to take, telling reporters that he had “tried to pass the most conservative stopgap measure possible” but “we didn’t have 218 Republicans”.
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.”
In an unusual move, senior Senate leaders from both parties, including minority leader Mitch McConnell, released a joint statement signalling their intention to “ensure the US government continues to provide” support to Ukraine in the coming weeks.
It came after Senator Michael Bennet – a Democratic member from Colorado, who backs more funding for Kyiv – held up Saturday’s proceedings in protest at the lack of guarantees for Ukraine included in the deal.
Congress has approved about $113bn (£92bn) in military, humanitarian and economic aid to Ukraine since Russia waged its full-scale invasion last year. President Biden has requested another $24bn.
Shutdowns happen when both chambers of Congress are unable to agree on the roughly 30% of federal spending they must approve before the start of each fiscal year on 1 October.
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.
Repeated efforts to pass spending bills in the House have been thwarted in recent weeks by rebel right-wingers.
The group has opposed short-term spending measures and pushed for making cuts by passing long-term spending bills with agency-specific savings, even though such bills stand little chance of advancing through the Senate.
Mr McCarthy had been extremely reluctant to rely on Democratic votes to pass the House’s bill until the last minute, given this would anger these hard-line conservative members of his party.
This drama is likely to be repeated again in less than seven weeks 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.
Mr McCarthy’s decision to rely on Democratic votes to pass the short-term bill was supposedly a red line that, if crossed, would prompt an attempt to remove the Speaker from his leadership position, by triggering a so-called motion to vacate.
Speaking to reporters on Saturday, Mr Gaetz said that Mr McCarthy’s speakership was “on some tenuous ground”, but he has yet to announce any plans to seek to oust the Californian congressman.
At his Saturday news conference, Mr McCarthy challenged those who oppose him to “bring it”, adding: “There has to be an adult in the room.”
The days ahead will reveal whether Mr Gaetz and company were serious about their threat – or just bluffing.