The US government has officially shut down for the second time this year because Congress failed to meet a deadline to vote on a new budget.
Senators, however, debated all night, and have voted to pass the bill, which must now pass to the House.
The 600-page plan proposes an increase in spending, by about $300bn, on defence and domestic services.
But lawmakers struggled to overcome last-minute objections from Republican Senator Rand Paul.
Federal funding for government services formally expired at midnight (local time).
Talks are continuing, with the hope that the shutdown can be rescinded before work begins Friday.
For that to happen, the plan must also be passed in the House of Representatives and signed by the president.
It is not yet clear how the House will proceed and how public services may be affected on Friday.
The federal Office of Personnel Management said government operations would "vary by agency" and employees should "refer to their home agency for guidance on reporting for duty".
CNN is reporting that if the shutdown is not averted, government agencies will still be able to call their employees in for a half day's work to make the shutdown go smoothly.
Why are budget hawks opposed?
While the spending bill's funding for the Pentagon has delighted the national security wing of the party, fiscal conservatives are up in arms about ramifications for the nation's debt.
In a doom-laden speech, Senator Paul angrily charged his fellow Republicans with fiscal profligacy.
"I ran for office because I was very critical of President Obama's trillion-dollar deficits," he said.
"Now we have Republicans, hand in hand with Democrats, offering us trillion-dollar deficits.
"I can't in all good honesty, in all good faith, just look the other way just because my party is now complicit in the deficits."
This would be "the very definition of hypocrisy", he added.
What's in this bill?
The 650-page spending plan was only unveiled on Wednesday night, so the finer details are unclear.
White House legislative affairs director Marc Short said the package would increase spending by "just shy" of $300bn.
The Washington Post puts the figure at half a trillion dollars.
The bill contains $165bn of additional defence spending and $131bn in domestic spending, including funding for healthcare, infrastructure and tackling the US opioid crisis, reports Reuters news agency.
The proposal would raise the US debt ceiling until March 2019.
Why are some Democrats unhappy?
Despite the support of their Senate leader Chuck Schumer, who says the budget accord will "break the long cycle of spending crises", some Democrats have complained that the bill does not address immigration.
The party's leader in the House of Representatives, Nancy Pelosi, said on Thursday morning she was opposed to the plan, but would not order rank-and-file Democrats to vote against it.
The California congresswoman has called for the bill to include a provision shielding so-called Dreamers, young immigrants who entered the US illegally as children, from deportation.
Her remarks came a day after she told the stories of immigrants for eight hours on the floor of the lower chamber in a record-breaking speech.
Obama-era guarantees for those immigrants were cancelled by US President Donald Trump and are set to become invalid next month.
Illinois representative Luis Gutierrez, one of the leading congressional advocates for immigrants, is urging colleagues to vote against the plan.
"Don't collude with this administration," he said.