Congress gave final approval on Wednesday to a bill to fund federal agencies into early next year, averting an immediate shutdown crisis but leaving the path toward a longer-term agreement on government spending as rocky as ever.

The Senate voted 87 to 11 to clear the temporary funding patch and send it to President Biden, who is expected to sign it, just days before a deadline at midnight on Friday. The measure was approved by the House on Tuesday with near-unanimous support from Democrats and over the opposition of almost half of House Republicans.

While dodging a short-term disaster, Congress will have only a few months to reach a governmentwide spending agreement. And a Republican mutiny over the measure on the House floor on Wednesday reflected how difficult it will be for the G.O.P. leaders to come to terms with Democrats on a more lasting plan.

The bill, known as a continuing resolution, sets up two deadlines in early 2024, with money for some agencies running out on Jan. 19 and the rest on Feb. 2. It continues funding at current levels and contains no policy conditions — two aspects that pleased Democrats and enraged far-right Republicans who have demanded steep cuts and conservative policy requirements.

“This Friday night there will be no government shutdown,” said Senator Chuck Schumer, Democrat of New York and the majority leader. “Because of bipartisan cooperation, we are keeping the government open without any poison pills or harmful cuts to vital programs — a great outcome for the American people.”

The tight timeline and the upcoming holidays leave lawmakers little breathing room to resolve the substantial differences between the two chambers and also among House Republicans. The internal G.O.P. rifts were on display yet again on Wednesday when rank-and-file Republicans blocked a separate spending bill from being considered.

Protesting Speaker Mike Johnson’s move a day earlier to rely on Democrats to push through the stopgap spending legislation, members of the House Freedom Caucus joined with Democrats to prevent legislation funding the Commerce and Justice Departments and science agencies from coming to the floor. The mutiny prompted leaders to adjourn the House abruptly and send lawmakers home for Thanksgiving.

It was the latest failure on spending bills under Mr. Johnson, and it reflected the ire of hard-line House Republicans that the temporary funding measure omitted their priorities.

“The swamp won, and the speaker needs to know that,” said Representative Chip Roy, Republican of Texas and one of the Republicans who voted Tuesday against the interim spending bill and blocked the funding measure on Wednesday.

Mr. Roy and 18 other Republicans were able to thwart consideration of the spending bill by breaking with their party to oppose the normally routine procedural measure to set rules for debate. The tactic was once considered unthinkable, but the hard right has resorted to it several times this year to defy its leaders.

In preventing a shutdown, Mr. Johnson essentially took the same bipartisan path that cost Representative Kevin McCarthy of California the speakership last month. Mr. Roy and his allies have said they have no intention at the moment of challenging Mr. Johnson’s hold on the gavel, but they reserved the right to continue raising procedural obstacles if he does not accommodate their demands.

The backlash from the Freedom Caucus came even though Mr. Johnson had pleaded with the hard-right lawmakers to extend him a grace period for advancing the short-term funding bill and to give him more time to try to move the House’s unwieldy spending bills.

“We’ve had enough,” said Representative Scott Perry of Pennsylvania, the chairman of the Freedom Caucus. “We’re sending a shot across the bow. We do this in good faith. We want to see these bills move. We want to see good, righteous policy, but we’re not going to be part of the failure theater anymore.”

A bloc of politically vulnerable New York Republicans also voted against the procedural step, saying the underlying bill contained cuts to law enforcement funding they could not support.

The legislation included a $1.2 billion cut to the Justice Department, including a $400 million cut to the F.B.I. that the White House said would result in the loss of 1,850 positions needed to combat gun violence and other crime.

Representative Nick LaLota, Republican of New York, described the move as part of a push by more mainstream Republicans to stand against far-right proposals.

“Folks from more purple districts like mine have had enough,” he said. “I exercise my right to defend myself politically.”

The House mutiny underscored how remote the prospect is of Congress coming to terms over spending by early February. If Mr. Johnson embraces the deep cuts and policy changes far-right Republicans are demanding, he may lose the support of more mainstream members of his conference and be unable to pass them. And even if he managed to push such measures through the House, they would be all but certain to die in the Democratic-led Senate.

Should Congress fail to pass its spending bills, an automatic 1 percent across-the-board cut would be imposed in April, an outcome that members of both parties say they want to avoid.

Kayla Guo and Luke Broadwater contributed reporting.