US lawmakers raced the clock to avoid a federal government shutdown before a midnight deadline on Friday after a meeting between President Donald Trump and Senate Democratic leader Chuck Schumer failed to produce a deal.
President Trump invited Mr Schumer to the White House for talks as a stopgap bill to fund the federal government through February 16 appeared headed to defeat in the Senate, where Democratic votes are needed to pass it.
Democrats have demanded that the bill include protections for hundreds of thousands of young illegal immigrants, but Republicans have so far refused.
Lawmakers huddled in meetings on Friday evening, but it was not clear if either side would blink before midnight.
Mr Trump said his meeting with Mr Schumer was "excellent" and that efforts were continuing. "Making progress - four week extension would be best," Mr Trump said in a tweet.
Shortly after Mr Trump's tweet, White House budget director Mick Mulvaney said he expected an agreement would be reached in the next 24 hours, indicating the government would shut down at midnight but reopen again at some point over the weekend.
Mr Schumer said his meeting with Mr Trump lasted about 90 minutes. "We discussed all of the major outstanding issues. We made some progress, but we still have a good number of disagreements. The discussions will continue," he told reporters.
The shutdown would begin on the first anniversary of Trump's inauguration as president. Leaders of both parties tried to blame each other for the impasse.
Past government shutdowns have done little lasting damage to the US economy, but put hundreds of thousands of "non-essential" federal workers on temporary unpaid leave. Shutdowns can also rattle financial markets.
"Essential" employees who deal with public safety and national security would keep working under a shutdown.
The Republican-controlled House of Representatives approved the stopgap spending measure late on Thursday, but it has been sidetracked in the Senate by the dispute over immigration.
The House recessed on Friday for a week-long break, but members were warned they could be called back for votes.
The last significant shutdown was in 2013, when government funding lapsed for 16 full days and about 800,000 federal workers were put on temporary leave.
This week's showdown follows a months-long struggle in Congress to agree on government funding levels and the immigration issue.
The federal government is operating on a third temporary funding measure since the current fiscal year began in October.
Democrats have demanded the bill include protections from deportation for about 700,000 illegal immigrants who were brought into the United States as children.
Known as "Dreamers" and largely from Mexico and Central America, these immigrants were given temporary legal status under the Deferred Action for Childhood Arrivals (DACA) program started by former President Barack Obama.
In September, Mr Trump announced he was ending the program and giving Congress until March 5 to come up with a legislative replacement.
Dick Durbin, the No. 2 Democrat in the Senate and who has taken a lead role in the immigration issue, said Republicans needed to sit down and negotiate and called on House Republicans not to leave town until the crisis was averted.
"I would beg them, don’t turn your back on your responsibility right here in Washington to work with us, to try to find a way forward," Mr Durbin said.
Mr Trump said in a morning tweet that Democrats were holding up a resolution over the immigration issue.
"Democrats are needed if it is to pass in the Senate - but they want illegal immigration and weak borders. Shutdowncoming?" he said.
Democratic Senator Tim Kaine told reporters that lawmakers were close to a longer-term deal and should not pass another 30-day funding measure. "We can get there, we’re close enough we can get there if we just stay on it," he said. "I think we can get one in the next few days."
Republican Senator Tom Cotton said he was willing to provide protection to DACA recipients in future negotiations.
"We have another six weeks to solve that problem. It doesn't really involve government funding," Mr Cotton told Fox News. "We should take those two issues up in sequence."
Republicans have a 51-49 majority in the Senate, but with Senator John McCain undergoing cancer treatment at home in Arizona they need at least 10 Democrats to reach the 60 votes required to pass a spending bill. In addition to strong Democratic opposition, at least three Republican senators have said they will not back the resolution in its current form.
Republican Senator Mike Rounds, who earlier said he could not back the bill, on Friday said in a statement that while the measure was "not ideal," he would support it after being assured that other legislation to adequately fund the US military would be raised soon.
Three Democratic senators who are up for re-election this year in states Mr Trump won in the 2016 presidential election said on Friday they would support the bill. But several other Democrats would still have to jump on board for passage.
Amid the deadlock, more senators were raising the possibility of merely approving enough new federal funds for a few days, as a tactic to put pressure on negotiators to then cut deals on immigration, defence spending and non-defence funding by next week.
But a White House aide said late on Friday that Mr Trump would not support a deal that keeps the government open for just four or five days.
Mr McConnell also shot down the idea. "Let's fund the government for a full month so we can actually get something done" and negotiate other issues including immigration, he said.