WASHINGTON — The House on Wednesday narrowly passed Republicans’ bill to raise the debt ceiling while cutting spending and unraveling major elements of President Biden’s domestic agenda, in a G.O.P. bid to force Mr. Biden to negotiate over spending reductions or risk a catastrophic debt default.

Facing his most significant challenge since being elected to his post, Speaker Kevin McCarthy barely cobbled together the votes to pass the bill, which was approved 217 to 215 along party lines.

The legislation would raise the debt ceiling into next year in exchange for freezing spending at last year’s levels for a decade — a nearly 14 percent cut — as well as rolling back parts of Mr. Biden’s landmark health, climate and tax law, imposing work requirements on social programs, and expanding mining and fossil fuel production.

Even Republicans conceded that their legislation was headed nowhere; Mr. Biden has threatened to veto it, and the measure is dead on arrival in the Democratic-led Senate. Without action by Congress to raise the debt limit, which is projected to be reached as early as this summer, the U.S. government faces a potentially catastrophic default.

But House Republicans regarded the vote as a crucial step to strengthen their negotiating position against Mr. Biden amid questions about whether Mr. McCarthy would be able to unite his fractious conference to pass any fiscal outline at all.

“We lifted the debt limit; we’ve sent it to the Senate; we’ve done our job,” Mr. McCarthy declared following the vote, visibly pleased with the outcome after a dayslong slog to rally Republicans around the plan.

Pushing through a debt limit increase was always going to be a heavy lift for Mr. McCarthy. Republicans reflexively resist raising the debt limit; in the past, many conservative G.O.P. lawmakers in both the House and Senate have left it up to Democrats and party leaders to cast the politically tough vote.

On Wednesday, it was unclear until the last votes were counted whether Mr. McCarthy would draw enough of his fellow Republicans to prevail, but party leaders managed to keep their conference largely united after days of arm-twisting and cajoling. Four Republicans ultimately voted against the bill; any more defections would have sunk the effort.

At the White House in advance of the vote, Mr. Biden repeated that he would not bargain over lifting the debt limit.

“I will meet with McCarthy, but not on whether or not the debt limit gets extended,” he said at a news conference, responding to reporters who asked whether he was willing to see the speaker. “That’s not negotiable.”

Nevertheless, Mr. McCarthy cast the bill as a way to bolster the party ahead of a showdown with the president. Along with last-minute changes to the legislation he made to placate Midwestern Republicans and the far right, he was able to win the votes of some lawmakers who have routinely voted against raising the statutory borrowing limit regardless of which party is in power, appeasing them by adding provisions to the bill to unwind aspects of Mr. Biden’s landmark Inflation Reduction Act and his plan to cancel student debt.

Republicans for months had tried and failed to unite around a budget blueprint outlining specific, detailed spending cuts they would demand in exchange for raising the borrowing limit. In a sign of the pessimistic outlook for a budget plan materializing, internal backbiting bubbled up last month after Mr. McCarthy privately derided the efforts of his deputies.

Instead of a budget, House G.O.P. leaders unveiled the Limit, Save, Grow Act — a substantially watered-down plan that dropped the party’s aspirations for balancing the budget and imposing draconian cuts — and urged their members to unite around the bill to try to force Mr. Biden to the negotiating table.

“The whole purpose of this is to compel the president to negotiate and to demonstrate to Washington, D.C., that Kevin McCarthy has the votes to raise the debt limit, and that we have shared priorities among all aspects of the Republican conference,” said Representative French Hill of Arkansas, a McCarthy ally.

Still, if anything, the process of pushing through the measure highlighted the deep divisions among Republicans on fiscal matters. Beseeching his colleagues privately to back the bill, Mr. McCarthy repeatedly told them to ignore the substance of the measure, which would never become law, and instead focus on the symbolic victory of passing any legislation to show Mr. Biden they were serious about their demand for spending cuts.

Republican leaders received political cover from an unusual wing — influential conservatives, including Representative Chip Roy of Texas, who stood on Wednesday in a closed-door meeting of lawmakers to urge his colleagues to vote for the bill.

Top officials were able to break through what would have been a fatal bloc of opposition to the bill after a late-night flurry of negotiating to nail down the votes, agreeing to jettison a provision rolling back tax credits that the Biden administration put in place for ethanol and moving up by a year, to 2024, the imposition of work requirements for Medicaid and food stamp recipients.

In the end, only four right-wing Republicans voted against the legislation, the most Mr. McCarthy could afford to lose and still have it pass. They were Representatives Andy Biggs of Arizona and Matt Gaetz of Florida, two of Mr. McCarthy’s chief antagonists in his prolonged fight to be elected speaker, as well as Ken Buck of Colorado and Tim Burchett of Tennessee.

Mr. Buck said his opposition was based on his view that the legislation did not go far enough in reducing federal debt.

“The issue to me is the Democrat budget plan in 10 years yields $58 trillion in debt,” he said. “The Republican plan yields $53 trillion in debt, and $53 trillion in debt is unacceptable to me. We go off the cliff at some point.”

Democrats assailed the measure as a cruel proposal that would hit the most vulnerable Americans with its spending reductions and new work requirements and would even reach into veterans’ programs.

“This is shameful,” said Representative Rosa DeLauro of Connecticut, the top Democrat on the House Appropriations Committee. “This default and cuts bill should not even come to this floor for a vote. Our veterans sacrificed for us.”

Senator Chuck Schumer, the New York Democrat and majority leader, dismissed the House bill as wasted effort and said Mr. Biden and Senate Democrats would refuse to negotiate over spending until Republicans agreed to pass a debt limit increase without conditions.

“Discussion of spending cuts belongs in talks about the budget, not for bargaining chips on the debt ceiling,” he said. “The speaker should drop the brinkmanship, drop the hostage taking, come to the table with Democrats to pass a clean bill to avoid default.”

Given the Senate Democratic resistance to the House plan, Senator Mitch McConnell, the Kentucky Republican and minority leader, said the final outcome remained in the hands of Mr. Biden and Mr. McCarthy.

“We have a divided government,” he said. “The president and the speaker need to come together and solve the problem.”

Jonathan Swan and Peter Baker contributed reporting.