WASHINGTON — They were so close.

As the votes rolled in Wednesday night to fund the government until February, a cluster of Democrats were singing Christmas carols in a corner of the Senate chamber. Senator Jeff Flake, Republican of Arizona, reflected on what he believed to be his last words in the Congressional Record. Everyone was making plans to head home for the holidays.

But within hours, President Trump torpedoed the compromise stopgap funding bill, pulling disgruntled lawmakers away from their families into one last partisan fray over what Mr. Trump took to describing as a barrier of artistic slats on the southern border — and the billions of dollars needed to build it. Once more, Congress was in the midst of a chaotic series of events, a week that encompassed a swooning stock market, an abrupt changing of the guard at the Pentagon, and decisions by the commander in chief to withdraw troops from Syria and Afghanistan.

Senator Bob Corker, the retiring Republican from Tennessee, couldn’t help but laugh at the absurdity of the theatrics of it all. “You can’t make this stuff up. You all have fun,” he told reporters on Thursday.

After a fractious, emotionally charged year that began with a shutdown, it seemed only fitting that the last gasps of the 115th Congress were marked by partisan whiplash, finger-pointing, and uncertainty all around.