A House-passed stopgap bill that would avoid a government shutdown fizzled out in the Senate late Friday night, leaving Congress negotiating frantically as the midnight deadline to fund the government passed.

The measure failed in a procedural vote by a 50 to 49 margin. Five Democrats — Joe Manchin of West Virginia, Joe Donnelly of Indiana, Heidi Heitkamp of North Dakota, Doug Jones of Alabama and Claire McCaskill of Missouri — had backed it. Four Republicans — Lindsey Graham of South Carolina, Jeff Flake of Arizona, Rand Paul of Kentucky and Mike Lee of Utah — opposed it. So did Senate Majority Leader Mitch McConnell for procedural reasons.

As nearly all Democrats and some Republicans opposed the measure that failed to work its way through Congress on Friday, lawmakers saw government funding lapse, at least temporarily. The proposal that failed in the Senate would have funded the government through Feb. 16 and reauthorized the popular Children's Health Insurance Program for six years.

As the vote remained open into early Saturday morning, several bipartisan senators appeared to confer about a way forward. McConnell and Senate Minority Leader Chuck Schumer then walked off the Senate floor together, only to return and continue talks with other senators. Numerous senators crowded around Schumer as the clock hit midnight.

Negotiations and potentially votes are expected to continue over the weekend and into next week. McConnell said he will offer an amendment to extend government funding until Feb. 8, which Sen. Lindsey Graham championed on Friday.

Many Democrats and some Republicans announced they would vote against a short-term deal, criticizing the continued use of stopgap bills rather than funding the government through more long-term, stable mechanisms. The minority party has also shown frustration about progress on talks toward a bipartisan immigration bill, which Democrats wanted to pass this week to protect hundreds of thousands of young undocumented immigrants from deportation.

The parties also remain divided over long-term defense and non-defense spending levels

"We're going to continue to do all we can," McConnell said on the Senate floor after the shutdown started. "We'll vote again so the American people know who stands for them. And when our friends across the aisle remember who it is they actually represent, we'll be ready to come together in a bipartisan discussion that will be necessary to clean up all of this mess."

The Senate needs to garner 60 votes for a spending bill. With 50 Republicans present, the majority GOP needed to win support from 10 or more Democrats, many of whom had threatened to oppose a short-term spending plan if they could not also pass a bill shielding young undocumented immigrants from deportation. (Sen. John McCain is away from Washington, receiving treatment for cancer.)

The bill's apparent failure in the Senate was the last step toward the first government shutdown since 2013.

In remarks following McConnell's comments, Schumer said he was "willing to compromise" with Trump on an immigration agreement and said he thought he had a deal with the president during a White House meeting Friday. The senator contended that Trump backed off of a possible immigration solution when he faced pressure from conservatives.

"Now all of this problem is because Republican leadership can't get to yes, because President Trump refuses to. Mr. President, President Trump, if you are listening, I am urging you: please take yes for an answer," he said, adding that the "blame should crash entirely" on the president's shoulders.

As funding looked set to lapse at midnight, White House press secretary Sarah Sanders released a scathing statement blaming Democrats for the shutdown.

"We will not negotiate the status of unlawful immigrants while Democrats hold our lawful citizens hostage over their reckless demands. This is the behavior of obstructionist losers, not legislators. When Democrats start paying our armed forces and first responders we will reopen negotiations on immigration reform," she said.

Schumer has argued for a bill that extended funding only for a few days, rather than a month, to give lawmakers more time to hash out a long-term plan. He met with President Donald Trump on Friday afternoon, and though he said their talks yielded "some progress," they did not reach a deal to keep the government open.

On Thursday night, majority House Republican leaders had to keep nearly all of their members in line in order to approve the short-term spending legislation by a 230 to 197 margin. With Democrats putting up a nearly unified front against the measure, GOP lawmakers cleared a bill that would fund the government for about a month.

Eleven Republicans opposed the legislation, while six Democrats supported it.

Trump had backed the short-term funding plan. Republicans this week put the burden on Senate Democrats to avoid a government shutdown.

"Now Democrats are needed if it is to pass in the Senate – but they want illegal immigration and weak borders," Trump contended in a tweet Friday morning. "Shutdown coming? We need more Republican victories in 2018!"

House Speaker Paul Ryan used the line of attack after the House passed the bill on Thursday night.

"Senator Schumer, do not shut down the federal government," the Wisconsin Republican said at a news conference.

The Democrats facing the most political peril in the vote are those who face re-election this year in states Trump won, including McCaskill, Heitkamp, Manchin and Donnelly.

If a shutdown occurs, McConnell intends to keep the Senate in session over the weekend and force those Democrats to face a series of difficult votes, according to Politico and NBC News.