WASHINGTON — A federal appeals court has handed a victory to the government’s beleaguered consumer finance watchdog agency, ruling that its director’s power isn’t excessive and the president shouldn’t have freer rein to fire that person.

The decision came Wednesday in the politically charged case involving the Consumer Financial Protection Bureau, a keen target of conservative Republicans. The nine-member panel of the U.S. Court of Appeals, with three judges dissenting, overturned a 2016 ruling by a smaller panel that would have made it easier for President Donald Trump to fire then-CFPB director Richard Cordray, an appointee of President Barack Obama.

The decision comes as the watchdog agency is engulfed in turmoil and confusion. Cordray stepped down in November before his five-year term ended, and Trump named White House budget director Mick Mulvaney as acting CFPB director. Mulvaney, taking on the second role, has moved to soften agency regulations on payday loans and slash its funding.

At the same time, Leandra English, the agency’s deputy director under Cordray and named by him as his replacement, has claimed that she — not Mulvaney — is the rightful acting director. That dispute also has wound up in federal court. A judge ruled in early January in favor of Trump and the White House, denying English an injunction to keep Mulvaney out of the job.

The next stop for the legal tussle over the director’s power and the Constitution could be the Supreme Court. In an unusual turn, the Trump Justice Department opposed the agency within its own government in the case and could be expected to appeal the latest decision.

Consumer groups and Democratic lawmakers exulted in the ruling Wednesday. Meanwhile, Rep. Jeb Hensarling, R-Texas, who heads the House Financial Services Committee and is the agency’s fiercest critic, said he was “deeply disappointed.”

At the same time, Hensarling said, “I take great solace in the fact that Mick Mulvaney can use his unchecked, unilateral powers to continue the agency’s transformation.”

In the case, CFPB opponents challenged a provision of the 2010 Dodd-Frank financial overhaul legislation allowing the CFPB director to be removed only “for cause” — such as neglect of duty — and not over political differences. They asserted that conflicts with the Constitution, which enables the president to remove officials for any reason.

In the ruling, the appeals panel found that the provision doesn’t violate the Constitution and doesn’t prevent the president from performing his constitutional duty to supervise the executive branch. Having a single person in charge of the CFPB is different from the pattern atop many other federal regulatory agencies of a multi-member commission, the ruling said, “but we cannot downplay the fact that Congress also required extensive coordination, expert consultation and oversight of the director. If much was given to the director, then much was also required.”

Cordray, who gave up the position to run as a Democrat for governor in Ohio, was the first and only director of the consumer agency. The CFPB has been swept up in partisan politics since its creation by the Dodd-Frank law that tightened supervision of Wall Street and the financial industry following the crisis and the Great Recession. Wall Street interests, the banking and consumer finance industries and Republicans in Congress have fiercely opposed and criticized the agency, accusing it of overreaching in its regulation.

Democrats and consumer groups defending the CFPB point to its record. The agency, with about 1,600 employees, has taken legal action against banks, mortgage companies, credit card issuers, payday lenders, debt collectors and others. The CFPB has said that over five years it has recovered $11.7 billion that it returned to more than 27 million harmed consumers. It has handled over a million complaints from consumers.