Almost all Democrats and a majority of Republicans overcame the opposition of G.O.P. conservatives to approve the bill under special expedited procedures that required a supermajority. That approach, hatched by Mr. Johnson in his first weeks as speaker, amounted to a gamble that a substantial number of Democrats would rally to help pass a package that Mr. Johnson’s own members were unwilling to back.
The vote was 336 to 95, easily clearing the two-thirds threshold required for passage. In the end, 209 Democrats and 127 Republicans joined to pass the bill. Ninety-three Republicans opposed it, as did two Democrats.
The final tally vividly reflected a dynamic that dogged both Mr. Johnson and his predecessor, Speaker Kevin McCarthy: The House G.O.P. lacks the political will to keep the government funded, forcing its leaders, operating with only a tiny majority, to rely on Democratic votes to do so or face the political backlash for a shutdown.
The Senate is expected to pass the legislation and send it to President Biden’s desk within days, and a White House official said Mr. Biden would sign it. Senator Chuck Schumer of New York, the majority leader, told reporters that he wanted the Senate to vote on the bill “as soon as possible.”
Despite criticism of the Johnson plan by the White House when it was released last weekend, Mr. Schumer said he had consulted with the administration and “both of us agreed, the White House and myself, that if this can avoid a shutdown, it will be a good thing.”
Approval of the bill means that government services will continue uninterrupted through the holiday season into early next year, staving off another self-imposed crisis just ahead of Thanksgiving.
But it buys Congress only a few more months before lawmakers find themselves in the same situation again. And the deep divisions among Republicans over government spending levels will not be easily resolved in the weeks to come.
The legislation would fund federal agencies at current spending levels with two different expiration dates: Jan. 19 for one set of government programs and Feb. 2 for another set. That timing would allow lawmakers more time to try to finish off the individual annual spending bills, as many conservatives have demanded. The bill did not include any military aid to Israel and Ukraine.
Mr. Johnson hailed the legislation as having broken an increasingly common practice in Washington of funding the government with one huge spending bill, known as an omnibus, a routine conservatives have long derided.
“We are not going to have a massive omnibus spending bill right before Christmas,” Mr. Johnson said. “That is a gift to the American people. Because that is no way to legislate. It is not good stewardship.”
In the days leading up to this week’s funding deadline, some hard-liners in Mr. Johnson’s conference had suggested that Republicans should let the government shut down and use that as leverage to try to force lower spending levels.
That was an argument that Mr. Johnson might have accepted as a rank-and-file member. In September, he was among a significant minority of Republicans who opposed the stopgap spending billadvanced by Mr. McCarthy, that ultimately led to his ouster.
But in his first major test as speaker, a post he won just three weeks ago, Mr. Johnson quickly moved to pull the government back from the brink of a shutdown, using the same formula that prompted his predecessor’s downfall.
“I want to cut spending right now, and I would like to put policy riders” on the bill, he said. “But when you have a three-vote majority — as we do right now — we don’t have the votes. So what we need to do is avoid the government shutdown.”
Democrats had previously panned the idea of a government funding bill that staggered funding for different agencies. But they ultimately supported the bill in the interest of averting a painful shutdown. They said they were relieved that Mr. Johnson had advanced a spending plan that neither cut funding for federal programs nor conditioned it on new policy measures.
“We have consistently made clear that a government shutdown would hurt the economy, our national security and everyday Americans during a very fragile time and must be avoided,” top Democrats wrote in a statement before the vote, led by Representative Hakeem Jeffries of New York, the minority leader.
Just six weeks ago, Mr. McCarthy turned to the same coalition to avert a shutdown and extend the funding deadline to Nov. 17. It was the final straw for hard-right Republicans who had distrusted and tormented Mr. McCarthy since he was elected to his post, and they ousted him for it.
Mr. Johnson inherited the same spending dilemmas that dogged Mr. McCarthy, a California Republican. Hard-right Republicans have insisted on loading up the individual spending bills to fund the government with deep cuts and conservative policy riders that mainstream, politically vulnerable Republicans have refused to support.
At the same time, some conservatives have flatly refused to back any sort of stopgap spending measure, including one Mr. McCarthy advanced in September that included drastic cuts to government programs — in many cases as much as 29 percent.
On Tuesday, some of the same hard-line conservatives who moved to oust Mr. McCarthy vented their anger at Mr. Johnson. The House Freedom Caucus, a group of approximately three dozen hard-right lawmakers, announced ahead of the vote that it would oppose the measure.
“It contains no spending reductions, no border security and not a single meaningful win for the American people,” the group wrote in a statement. “Republicans must stop negotiating against ourselves over fears of what the Senate may do with the promise ‘roll over today and we’ll fight tomorrow.’”
But in a sign that there was little appetite to depose Mr. Johnson for relying on Democrats to pass the legislation, as they did to Mr. McCarthy, the lawmakers continued, “While we remain committed to working with Speaker Johnson, we need bold change.”
Representative Chip Roy of Texas, an influential conservative, said that some of his colleagues believed Mr. Johnson’s promise that he wouldn’t advance another stopgap bill to fund the government and was only doing so because he had only become speaker a few weeks ago.
“If you’re storming the beaches of Normandy and the commanding officer goes down and somebody else takes over you don’t say, Oh, well you get a honeymoon period,’” Mr. Roy said. “You got to pick it up and go. And so for me, this was a strategic failure. We should not do this. You should not be passing $400 billion under suspension of the rules. And that’s what we’re going to be doing.”
He continued: “We’re trying to give the speaker a little grace, but today’s a mistake, right out of the gate.”
Reporting was contributed by Carl Hulse, Kayla Guo, Luke Broadwater, Annie Karni and Robert Jimison.