The US government careened toward shutdown on Friday night (local time) in a chaotic close to Donald Trump's first year as president.
An eleventh-hour effort to stave off the shutdown for four weeks appeared to fall well short in the Senate, and legislators pre-emptively traded blame as the midnight deadline neared.
Enough senators voted against a stopgap measure to ensure the closure of all but essential operations nationwide.
But the Republican-led Senate was holding the vote open as nearly an hour ticked by and the midnight hour neared, seemingly accommodating the numerous discussions among leaders and other lawmakers away from the chamber's floor.
Up to that point, Democrats largely held together to block the funding legislation, digging in on their insistence that the spending bill include protections for some 700,000 younger immigrants facing deportation.
After hours of heated closed-door meetings and phone calls, including with the White House, the Senate scheduled its late-night vote on a House-passed plan.
It failed by far to gain the 60 votes to break a Democratic filibuster, with a handful of red-state Democrats crossing the aisle to support the measure and some Republicans voting in opposition.
Even before the vote, Mr Trump was pessimistic, tweeting, "Not looking good" and blaming the Democrats who he said actually wanted the shutdown "to help diminish the success" of the tax bill he and fellow Republicans pushed through last month.
The President watched the results from the White House residence, dialling up allies and affirming his belief that Democrats would take the blame for the shutdown, said a person familiar with his conversations but not authorised to discuss them publicly.
The election-year standoff marked a test of the president's much vaunted deal-making skills - and of both parties' political fortitude.
Republicans, who control both Congress and the White House, faced the prospect of being blamed for the display of dysfunction - just the fourth shutdown in a quarter-century.
It could also threaten to slow any GOP momentum after passage of the party's signature tax law.
Democrats, too, risked being labelled obstructionist. Republicans branded the confrontation a "Schumer shutdown" and argued that Democrats were harming fellow Americans to protect "illegal immigrants".
Mr Trump had brought Senate Democratic leader Chuck Schumer to the White House Friday afternoon in hopes of cutting a deal.
But the two New Yorkers, who pride themselves on their negotiating abilities, emerged without an agreement, and Republicans and Democrats in Congress continued to pass off responsibility.