(CNN) -- The Senate late Friday cleared a bill to fund the government through the end of April, narrowly averting a shutdown.
The 63-36 vote came just before a midnight deadline when the government could have run out of money.
Final passage came after a procedural vote to advance the measure was narrowly adopted. Needing 60 votes, it cleared 61-38. The vote took nearly an hour and was tense and uncertain to the end as senators weighed political and parochial interests in deciding which way to vote. Party leaders and whips, trying to save the must-pass bill, worked their members furiously. President Barack Obama signed the measure into law early Saturday.
The late night action came after a day of back-channel negotiations aimed at alleviating concerns from coal-state Democrats who wanted a longer extension of expiring health benefits for retired coal miners. Democrats failed to secure enough votes to that extension.
The battle centered on how long the government should extend health benefits for retired coal miners, as the Democrats called for an extension lasting one year, rather than the four months in the current proposal. And it amounted to the most intense partisan squabble on Capitol Hill since the general election, where Democrats struggled to win over white, working-class voters.
Democratic Sen. Joe Manchin of West Virginia, who faces reelection in 2018 and is under consideration for a job in Donald Trump's administration, took to the Senate floor Friday evening and demanded that his colleagues block the funding bill, which is needed to keep the government open past midnight.
"We've been working and fighting and really clawing for this," Manchin said. "But we've got some friends on the other side who believed it wasn't an emergency." Still, Democrats privately and publicly conceded they were unlikely to win over the 41 votes needed to shut the government down.
"I don't think we are going to get to the 41," Manchin said at a news conference Friday evening.
What Democrats got from the exercise is unclear. Democrats contended they had elevated the issue, and hoped that their aggressive push would pressure top Republicans to cut a deal on a permanent solution early next year. But they did not get the legislative fix they had been demanding.
During a caucus meeting Thursday, Senate Democratic leaders and coal-state Democrats agreed to use a threat of a shutdown to bring attention to the issue and push for a longer extension in January, a senior Democratic aide said.
"Our intention was never, never, ever to shut this place down," Manchin told CNN.
Added Sen. Mark Warner of Virginia: "We're not going to shut down the government on this issue."
The late-evening developments come as Senate Republicans and Democrats engaged in behind the scenes negotiations to try to head off a shutdown at midnight.
"I'm hopeful we'll wrap it up this evening but I don't have anything to announce yet," Sen. John Cornyn of Texas, the second ranking Senate Republican, told reporters.
In a sign of possible progress that a disruption to government services could be averted, Cornyn said discussions were underway between GOP leaders and Manchin of West Virginia, the lead Democrat pressing for changes to the health insurance program.
"We're working through third parties. Third party negotiators," Cornyn said. "I haven't talked to him directly but there are conversations taking place between leadership on the Democratic side and this side."
Republicans argued McConnell, who represents miner interests in his home state of Kentucky, has already committed to work to extend the health insurance for a full year, which is the central demand of Manchin and the Democrats backing his effort. Republicans note that McConnell initially pushed to get a one year extension into the funding bill and has spoken on the floor about his desire to extend it that long.
Sen. Sherrod Brown of Ohio, one of the leaders of the effort, told CNN that the GOP would squarely to be blame if there were a shutdown. Asked if he had the support to block a bill, Brown said: "I don't have any idea what we have. I know that the support has been stronger than I expected from Democrats and from some Republicans that will vote with us."
At issue is whether to extend the miners' insurance program -- which serves retired miners and their spouses -- for one year or for just for the four month length of the GOP-authored spending bill, which is known as a continuing resolution or CR.
One person who is trying to build support for the measure is Manchin who was holed up in his office Friday talking to Democrats and some Republicans urging them to block the CR. Manchin, a moderate, had been scheduled to meet with Trump in New York Friday about a possible job in his administration but it was postponed until Monday so he could deal with the miners' issue.
Democrats are worried Manchin might leave the Senate to work for Trump, which could lead to a Republican pick up of his Senate seat.
Manchin is leading a pack of coal Senate Democrats -- including Brown, Heidi Heitkamp of North Dakota and Bob Casey of Pennsylvania, each of whom is up for re-election in two years --- to bolster the insurance benefits. Manchin has the support of at least one Republican, his fellow West Virginia Sen. Shelley Moore Capito, while GOP Sen. Rob Portman of Ohio is weighing whether to join the Democrats as well.
But even Manchin wouldn't predict that he has the 41 votes needed to scuttle the spending bill and force a change to help the miners.
"We have a strong commitment from our caucus, I can tell you that. Very strong," is as far as Manchin would go when asked specifically late Thursday if he had 41 votes.
One key Democrat has joined Manchin's battle. Incoming Senate Democratic leader Charles Schumer of New York vowed Thursday, "We are going to win this fight."
There could be political dividends for Democrats making a full-throated fight for the miners, even at the risk of a potentially risky shutdown. Trump won big in coal country and Democrats would love to claw back some of those working class voters.
As he opened the chamber for what's been expected to be the final legislative day of the year, McConnell implored Democrats to accept the miners provision as it is and not recklessly shutdown the government over it.
"It's been my intention that the miner benefits not expire at the end of April next year," said McConnell. I'm going to work with my colleagues to prevent that. But this is a good time to take 'yes' for an answer. We should pass the CR without delay."
McConnell noted that the bill passed the House with overwhelming bipartisan support Thursday, a sign House Democrats were okay with the four month extension.