It was a vivid drama of personalities and power, shifting alliances and clashing egos, played out live on the Senate floor as the government barreled toward a shutdown. With television cameras rolling late Friday night, senators talked, wrangled, grinned and growled through a sequence of 11th-hour negotiations, ultimately fruitless but revealing to the end.

By the time it was over early Saturday, government funding had run out for the first time since 2013. Yet for more than two hours, the public had gotten a rare glimpse of a usually scripted group jostling and unscripted, with lawmakers negotiating face-to-face with members of their own party and the other, exchanging offers, deliberating and trying to make a deal.

Success eluded them in the moment. Still, numerous senators and aides said that Friday night's spectacle laid the groundwork for a potential deal on immigration and federal funding.

"I felt I was actually in a deliberative body," said Sen. Lindsey O. Graham (R-S.C.), who had a starring role in the proceedings as he shuttled back and forth between at least three different packs of lawmakers. "Rather than giving floor speeches and making cable TV appearances, we were actually deliberating. We fell short, but Friday night made me and a bunch of senators talk to each other."

The Senate floor had sat mostly empty throughout Friday except for the occasional speaker expressing outrage about the government shutdown looming at midnight — eight hours away, five hours away, three hours and then barely two. Finally, a little after 10 p.m., Senate Majority Leader Mitch McConnell (R-Ky.) called his colleagues to the chamber for the last minutes of debate and a vote to move forward on a short-term bill to keep federal agencies running.

Senate staffers leave the Capitol around 1:40 a.m. on Saturday after hopes to avert a government shutdown were dashed. (Michael S. Williamson/The Washington Post)

At 10:14 p.m., the vote began and within 30 minutes the roll call was nearly complete: 50 senators had voted aye, 46 Republicans and four Democrats; 48 had voted no, 44 Democrats and four Republicans. McConnell, however, was far short of the 60 votes needed to choke off the Democratic-led filibuster and keep the government open. Rather than gavel the vote shut, McConnell allowed a groundswell of last-minute negotiations to ensue.

Sen. Cory Gardner (R-Colo.) said the atmosphere grew frenzied, with each senator searching for the latest bit of information.

"I talked to everybody on the floor," Gardner said. "Everybody was trying to get a deal together, so we were all talking about what that deal could be."

Earlier in the day, Graham, Sen. Susan Collins (R-Maine) and a group of more than a dozen other lawmakers of both parties had gathered in Collins's office to mull a proposal that would keep the government open until Feb. 8, a week earlier than the bill on the floor Friday night. That would give negotiators another three weeks to sort out all of the issues of concern: How much money for the federal budget; how much to send to storm-ravaged states; the reauthorization of the Children's Health Insurance Program (CHIP); and a resolution to the fate of young undocumented immigrants known as "dreamers."

These moderates fanned out as the clock neared midnight to try to put the finishing touches on the deal, with Graham, Sen. Jeff Flake (R-Ariz.) and others conferring separately and together with shifting groups of fellow lawmakers of both parties, and asking them to sign on to the Feb. 8 proposal.

As the senators huddled, Minority Leader Charles E. Schumer (D-N.Y.) sat in his chair, glasses propped low on his nose, talking with aides and several Democratic colleagues who came and went. Several times, Flake approached, discussing the progress of the talks.

Just across the aisle, McConnell mostly stood with his deputy, Senate Majority Whip John Cornyn (R-Tex.), and several other Republicans who came by to chat, including Sen. Tom Cotton (R-Ark.). McConnell also spoke for a while with Sen. Angus King (I-Maine), a former Republican who caucuses with Democrats and grew so angry with the lack of progress that he later temporarily blocked the Senate from adjourning for the night.

Just before 11 p.m., Schumer bounded down the center aisle and pulled McConnell off the floor and into a lobby behind the chamber, just the two leaders talking.

The central dispute, those officials said, was that Schumer and the Democrats wanted a shorter-term funding bill, to Jan. 29 or Jan. 30, trying to wrap up the deal before Trump's state-of-the-union address. McConnell refused, saying that wasn't enough time to complete all the various pieces of the legislative puzzle.

About 10 minutes later they reemerged as the scrums expanded throughout the chamber.

Schumer darted around the chamber for a few more minutes, talking to senators in both parties and sounding hopeful that a deal might be in the offing. At 11:10 p.m., the two Senate leaders headed off the floor again, to the same lobby, for another one-on-one talk. Before he left the floor, Schumer stopped and fist-bumped Graham.

But this Schumer-McConnell meeting did not last long, and after a few minutes Schumer took his seat in the front row of the Democratic side of the aisle.

The body language told the story: Schumer, slumped in his seat, sat and listened as Graham gathered nearly 20 senators of both parties around the New Yorker and made a final plea not to let the government shut down. But Democrats sometimes shook their heads "no." At times, senior Democratic aides interjected.

By then, senior aides and senators in both parties had sent notes to reporters that a deal had not come through and the shutdown would be commencing at midnight.

Later, senators and aides said that in the course of discussions with Schumer, McConnell had spoken by phone with House Speaker Paul D. Ryan (R-Wis.). Though the parties dispute what was said, Ryan's call with McConnell is widely seen as a key moment that ended any chances of a deal Friday since Ryan was not going to change his position on keeping immigration talks separate from funding talks, officials said.

"I did see when Leader McConnell and Minority Leader Schumer started having a brief discussion on the floor and left the floor. You saw that. I thought, 'That's encouraging,' " said Sen. Steve Daines (R-Mont.). He chuckled, looking back on that brief spurt of optimism. "Well, I was hoping we'd come to some outcome that didn't involve shutting down the government. Then it was midnight. We were shut down."

Amid the main conversations, anyone with a view of the whole room could see several other intriguing political subplots playing out in real time.

Just hours before the vote, the Justice Department announced plans to retry Sen. Robert Menendez (D-N.J.) on federal corruption charges. Menendez had returned to the fold in the Senate after a mistrial in the fall. But by Friday night, he was out of the loop once again, a potential liability to his party at a moment when the longest-serving Latino in the Senate should have been front-and-center.

As his colleagues debated a way forward, Menendez spent most of the night in his chair, staring straight ahead.

And in the back corner of the Republican side of the chamber, two senators who played lead roles in the 2013 government shutdown, Sens. Ted Cruz (R-Tex.) and Marco Rubio (R-Fla.), sat watching other colleagues sort it out. In 2013, Cruz launched an overnight filibuster — including a dramatic reading of Dr. Seuss's "Green Eggs and Ham" — that led to the 16-day spending impasse. On Friday night, they sat together as Cruz told jokes that earned loud laughs from Rubio, other Republican senators and even Sen. Cory Booker (D-N.J.), who joined them briefly.

"Ted was like the leader of the shutdowns in the past. . . . He was scolding me for being too extreme. It was fun," Graham, who voted against the funding bill, laughed later. "I was the Ted Cruz for the moment!"

The talks went on so long that the clock on the clerks' desk ran out of figures to record the roll-call vote. So, the clock stood at 99:59, as Graham and others kept talking.

It did not matter — by then, it was already past midnight. The government had shut down.