WASHINGTON — Congress gave final approval on Thursday to a stopgap spending bill that would punt the threat of a government shutdown to just before Christmas, setting up a potential clash over federal spending just as the House could be weighing whether to impeach President Trump.

Hours before funding was set to lapse on Thursday, the Senate voted to postpone the spending fight, approving a measure to extend funding through Dec. 20 for all federal government departments and agencies, as well as a number of health care and community programs. That deadline sets up a potentially climactic series of votes in late December, when lawmakers could be considering impeachment articles against Mr. Trump while racing to avert a holiday season government shutdown.

Lawmakers remain divided over funding Mr. Trump’s signature promise to build a wall at the southern border — the same issue that led to the pre-Christmas government shutdown nearly a year ago, which stretched into January and became the nation’s longest. By a vote of 74 to 20, the Senate agreed to the temporary measure, haunted by the consequences of the 35-day shutdown that lasted into January. The measure received a slim bipartisan majority in the House this week, and the president signed the bill into law on Thursday.

“These are things we must do,” said Senator Mitch McConnell, Republican of Kentucky and the majority leader, lamenting the lack of a full-year spending package as well as other legislative priorities at a news conference on Tuesday.