WASHINGTON — Congress on Tuesday approved a bill to repair the formula for reimbursing Medicare physicians, marking a rare bipartisan achievement just in time to head off a 21 percent cut in the doctors’ pay.

Final action came as the Senate voted 92-8 to approve the so-called “doc fix.” The House of Representatives had acted over two weeks ago. The bill now goes to President Barack Obama, and he is expected to sign it into law.

The measure, drafted last month by Republican House Speaker John Boehner and Democratic Minority Leader Nancy Pelosi, appeared to be the first major legislative accomplishment of the 2015-2016 Congress, suggesting some progress toward easing years of gridlock on Capitol Hill.

In a statement, Obama applauded lawmakers for passing the bill, saying it would strengthen the health care system. “I will be proud to sign it into law,” he said.

The bill would replace a 1990s formula that linked Medicare doctor pay to economic growth, with a new formula more focused on quality of care. It also would require means-testing of Medicare beneficiaries so higher income people pay higher premiums.

“I applaud the Senate for passing legislation that will help strengthen Medicare and I am pleased that the President will sign it into law,” said U.S. Rep. Bruce Polquin, R-Maine. “While it may not be perfect, this bill is the first-step in making Medicare more accessible for our seniors. It’s imperative for Congress to protect and preserve Medicare for our seniors and future generations.”

One of the government’s largest social safety net programs, Medicare is health insurance that serves 54 million elderly and disabled people.

The old formula for paying Medicare doctors has been a problem for years as health care costs outpaced economic growth. Congress had repeatedly addressed the problem with a long series of temporary “doc fix” patches. The new formula is intended to be a lasting change.

The federal government warned Congress last week that it must act before April 15 or thousands of Medicare doctors nationwide would face a 21 percent pay cut under the old reimbursement formula.

The deadline for action actually had been April 1, but because Medicare doctors’ claims generally take at least 14 days to be paid by the government, the pay cuts were not expected to be implemented before April 15 — Wednesday.

The measure passed the House overwhelmingly in March but because it expands the federal deficit, it was greeted skeptically by deficit hawks in the Senate.

They labeled the bill irresponsible because it would add an estimated $141 billion to the U.S. debt over the next 10 years, according to the Congressional Budget Office.

But an amendment sponsored by Sen. Mike Lee requiring Congress to find ways to pay for the “doc fix” by the end of this year, failed to pass Tuesday on a vote of 42-58.

The legislation includes a two-year extension of the Children’s Health Insurance Program for low-income children and a two-year extension of funding for community health centers.

Both were high priorities for Democrats, and they tried to extend them to four years, but their amendments failed. They also tried to take out some anti-abortion language, but the amendments failed.

Health care groups were leaning hard on the Senate to approve the measure, and Senate Majority Leader Mitch McConnell argued Tuesday for approval, noting it included more means testing of Medicare beneficiaries.

Boehner also urged the Senate to pass the House bill on Tuesday, saying the House had no intention of acting again on the measure if the Senate amended it.