Congress has agreed to shield patients from many big, unexpected medical bills — a practice that consumers and politicians have bemoaned for years but that eluded a federal solution until now.

A ban on what is known as surprise billing is woven into a pandemic relief package, which lawmakers approved late Monday. The ban is based mainly, but not entirely, on a bipartisan accord this month among three House committees and one in the Senate that had each tried to outlaw the practice before.

The issue involves often-large bills that patients are sent for care they did not realize was outside their insurer’s network. Such bills have become increasingly common even when patients use an in-network hospital. At times, emergency room visits can lead to bills for treatment by a physician who has not agreed to participate in the network. And when care is planned in advance, such as for surgeries, patients do not always know that some medical specialists, such as anesthesiologists, can be outside a network.

The ban, to take effect at the start of 2022, will be “the biggest victory for consumers since the Affordable Care Act,” said Rep. Frank Pallone Jr. (D-N.J.), chairman of the House Energy and Commerce Committee, which approved the first unsuccessful federal legislation in mid-2019. “It’s now up to the provider and the insurance to figure this out. It’s not the consumers’ problem,” Pallone said in an interview Monday.

Buffering patients from such unexpected bills is a rare health policy issue that Democrats and Republicans have both endorsed in theory. In May 2019, President Trump urged Congress to help protect consumers from surprise bills when polls showed that health-care costs would be a dominant issue in this year’s presidential election. President-elect Joe Biden also has called for an end to the practice.

Still, repeated efforts on Capitol Hill to protect consumers have bogged down because of intense disputes among different segments of the health-care industry. “Patients have effectively been held hostage to a high-stakes battle among interest groups,” said Larry Levitt, executive vice president of the Kaiser Family Foundation, a health policy group.

Most health-care constituencies have agreed that consumers should not have to pay more than their insurer’s network rates for specific charges. The dispute has been over how to resolve the amount of the bill an insurer must pay for whatever is left over.

In the end, the agreement relies on outside arbitrators, a method favored by many hospitals and other providers of care. It also is supported by private equity firms, which have bought up physicians’ practices and removed them from insurance networks. The firms have mounted an aggressive lobbying campaign to try to block any approach that would substantially inhibit what can be charged.

The other approach, which lost out in the agreement, involves resolving billing disputes through “benchmarks,” consisting of the typical price a given insurer pays for a medical service in that geographic area. Evidence suggests that this approach has led to lower payments in states where it has been tried.

House Ways and Means Committee Chairman Richard E. Neal (D-Mass.) has adamantly favored arbitration in aligning with hospitals and blocking other committees’ approaches. Neal essentially won out, with the final version, unlike the committees’ agreement, permitting providers and insurers to go before an arbitrator for any amount, with each proposing a payment level if they cannot negotiate one on their own.

The legislation does not specify who the arbitrators should be, leaving that to the Department of Health and Human Services to spell out before the ban takes effect.

The legislation says that, in deciding on a fair payment, an arbitrator must take into consideration what the local rates are for in-network care. And unlike in the committees’ agreement this month, it says an arbitrator will not be allowed to consider the rates paid by Medicare and Medicaid — large government insurance programs that often pay hospitals, doctors and others considerably less.

“This is a good solution to a serious problem,” said Tom Nickels, the American Hospital Association’s vice president for government relations and public policy. He said estimates, including one by the Congressional Budget Office, projected that benchmark approaches would lower what hospitals and physicians were paid for in-network services, as well as for the out-of-network ones at issue in surprise bills.

On the other hand, Matt Eyles, president of America’s Health Insurance Plans, said in a statement, “We remain deeply concerned that hard-working American families and business will face increased costs and higher premiums as private-equity firms exploit arbitration processes.”

Research has found that unexpected bills for out-of-network care have been an escalating problem. A large analysis of emergency department visits by a sample of patients with private insurance showed that the proportion that led to such bills had increased from 32 percent in 2010 to 43 percent by 2016.

A study this year by the Kaiser Family Foundation of millions of insurance claims found that nearly 1 in 5 emergency room visits nationwide led to at least one unexpected bill for care outside the patient’s insurance network. When an emergency room visit led to a hospital admission, about 1 patient in 6 ended up with such a bill.

The Affordable Care Act, created in 2010, took a small step toward shielding patients. The health-care law says that no matter where a patient goes to an emergency room, their insurer may not charge them a larger co-payment than if the hospital were participating in the health plan. That does not, however, prevent out-of-network hospitals from sending large bills for the amount beyond what insurance covers. Nor does it shield patients if they are admitted to the hospital.

Nine states have created their own protections from surprise medical bills, and four more have enacted ones not yet in effect. However, the state laws do not help people with health benefits from self-insured companies — most people with private coverage.

The Congressional Budget Office estimates the federal protection will save $18 billion in a decade. That money, Pallone noted, will be used to aid community health centers, to ward off smaller reimbursements to hospitals in rural and underserved urban places, and for other efforts to help people in poverty.