By Ginger Gibson, Richard Cowan and Humeyra Pamuk

WASHINGTON (Reuters) - A partial U.S. government shutdown loomed at midnight on Friday as President Donald Trump's fellow Republicans in the Senate failed to secure the votes needed for a bill with $5 billion he has demanded for a border wall fiercely opposed by Democrats.

Trump said the impending shutdown of key parts of the federal government could last "a very long time," and he sought to blame Democrats. They, in turn, put the blame squarely on him for his demand for wall funding after previously indicating support for bipartisan legislation that passed the Senate without such money.

"President Trump has thrown a temper tantrum and now has us careening towards a 'Trump shutdown' over Christmas," Senate Democratic Leader Chuck Schumer said on the Senate floor.

"You're not getting the wall today, next week or on January 3rd, when Democrats take control of the House," Schumer added.

Hours before the deadline, lawmakers met with Vice President Mike Pence and other White House officials in a last-ditch effort to find a compromise government funding bill acceptable to both political parties and Trump. There was little indication any such agreement was at hand, but senators said talks would continue.

Before meeting with Senate Republicans at the White House, Trump wrote on Twitter that "Democrats now own the shutdown," despite having said last week that he would be "proud" to close the federal government over the issue of border security and "I'll be the one to shut it down."

Congressional funding for about one-quarter of the federal government's programs expires at midnight (0500 GMT), and a shutdown would ensue if Congress, controlled by Trump's fellow Republicans, does not pass legislation to provide money to keep the agencies open.

Negotiators were discussing $1.6 billion for a range of border security measures - not specifically for a wall - and retaining financial assistance for areas hit by natural disasters that was added by the House of Representatives, according to a Republican Senate aide.

Story continues

That $1.6 billion would only be $300 million more than the amount the Senate approved in a temporary funding bill it passed late on Wednesday.

"It's possible that we'll have a shutdown. I would say the chances are probably very good," Trump said at the White House.

"We're going to get a wall," Trump added.

A wall along the U.S.-Mexican border to combat illegal immigration and drug trafficking was a key Trump campaign promise in the 2016 election, when he said it would be paid for by Mexico, and he sees it as a winning issue for his 2020 re-election campaign. Democrats oppose the wall, calling it unnecessary and ineffective.

A Schumer spokesman said the senator met with Pence, Trump's new chief of staff, Mick Mulvaney, and Trump son-in-law and adviser Jared Kushner.

Republican Senators Lamar Alexander and Marco Rubio expressed frustration with what they said was a shifting position by the White House. Rubio said that earlier in the week the Republicans went with their funding bill, which included $1.3 billion for general border security but nothing specifically for a wall, because Pence had told them the White House was open to such a proposal.

"We had a reasonable path and there was every indication from the president that he would sign it," Alexander said.

PROCEDURAL VOTE

Trump summoned Senate Republicans to the White House on Friday morning to push for his wall funding before they took up procedural votes on whether to consider the bill passed by the House. The procedural vote stretched over several hours because many senators left Washington to start their Christmas break, thinking the temporary funding issue was settled on Wednesday, and had to return to the Capitol.

The measure succeeded with Pence casting a tie-breaking vote, but Senate Majority Leader Mitch McConnell said the vote merely ensured that the White House and Democrats could keep discussing a potential compromise to avert a shutdown.

Earlier in the week the Senate, where Republicans have a 51-49 majority, passed a short-term government funding bill that included no money for the wall. On Friday Senate Majority Leader Mitch McConnell urged his members to vote for a bill that was approved by the House on Thursday to give Trump $5 billion toward building the wall on the Mexican border.

In a series of early-morning tweets on Friday, Trump called on McConnell to use the "nuclear option" to force a Senate vote on legislation with a simple majority, rather than the standard "supermajority" of 60 votes. But there was not enough support among Republican senators to do so.

BAD DAY ON WALL STREET

The possibility of a government shutdown fed investor anxieties that contributed to another down day on Friday for U.S. stocks. The Dow Jones Industrial Average fell 1.82 percent, the S&P 500 lost 2.06 percent and the Nasdaq Composite dropped 2.99 percent.

The showdown added to tensions in Washington as lawmakers also grappled with Trump's sudden move to pull troops from Syria, which prompted Defense Secretary Jim Mattis to resign and furthered concerns over the investigation of Russian meddling in the 2016 election that Trump won.

Three-quarters of government programs are fully funded through the end of the federal fiscal year next Sept. 30, including those in the Defense Department, Labor Department and Health and Human Services. But funding for other agencies, including the Department of Homeland Security, the Justice Department and the Agriculture Department, was set to expire at midnight on Friday.

A partial government shutdown could begin with affected agencies limiting staff to those deemed "essential" to public safety. Such critical workers, including U.S. border agents, and nonessential employees would not get paid until the dispute ends. National parks also would close unless the government declares them essential.

More than half of the 1,700 people who work for the executive office of the president would be furloughed.

(Reporting by Richard Cowan, Ginger Gibson, Roberta Rampton and Susan Heavey; Writing by Will Dunham and Bill Trott; Editing by Jonathan Oatis and Cynthia Osterman)