Walter Shaub Jr. announced his resignation as director of the Office of Government Ethics on Thursday, plunging the federal government’s top ethics watchdog agency into limbo. President Trump now has the chance to appoint an accommodating loyalist who’d give him far less trouble than Mr. Shaub has. Or he could surprise us, and name another independent director committed to the ethical rules of public service. The president’s past behavior doesn’t offer much hope, but it would be in his long-term interest to choose a director with integrity.

The 70-person O.G.E. works with some 4,500 executive branch ethics officials whose goal is preventing conflicts of interest among 2.5 million civilian federal employees. The energy, commitment and character of the person at the top is crucial to the office’s success, not least because it has no real enforcement power. Its influence derives from a mix of financial disclosure rules, public pressure and, ideally, White House support for its mission of ensuring that civil servants act on the behalf of Americans, not themselves.

The office has had no such backing in its grinding battles with the Trump administration, whose appointees, some of the wealthiest nominees in history, resisted demands that they sell off businesses and assets that presented potential conflicts of interest. After a long confrontation, Mr. Shaub won one battle, forcing the administration to disclose the names of officials in Mr. Trump’s inner circle who had been granted waivers from the White House’s pledge to avoid conflicts of interest. It was a hollow victory, since all those officials were allowed to go about their business as usual.

Mr. Shaub, who tangled as well with nominees in the George W. Bush and Barack Obama administrations, is a person of great determination and deep legal knowledge, and it’s unfortunate that he is leaving before his term expires in early January, instead of fighting to the end. He says his new job, for the nonpartisan Campaign Legal Center, offers him greater freedom to press for tighter ethics laws.

Mr. Shaub and his team tried and failed to persuade Mr. Trump to sell off his businesses, a move required for his cabinet but not for the chief executive. Mr. Trump’s determination to leverage his presidency for personal profit sets him apart from his modern predecessors. Lawsuits over foreign government payments to the Trump International Hotel in Washington, and near-constant criticism of his and his family’s ethical shortcomings, are a direct result of their failure to separate public service and personal gain. Tighter rules requiring such separation are something that a new and independent ethics director could champion.

Alas, Mr. Trump has shown a preference for friendly partisans in oversight jobs, most recently his choice of Henry Kerner to lead the Office of Special Counsel, a small agency charged with protecting federal government whistle-blowers and enforcing the Hatch Act, which prohibits executive branch employees from engaging in political activity. Mr. Kerner, a former Republican staff member on the House Oversight and Government Reform Committee, is assistant vice president for investigations at an anti-regulatory group called Cause of Action.

The group gained some notoriety recently when it filed a lawsuit asking the Environmental Protection Agency for encrypted messages from career employees who, according to news reports cited by Mr. Kerner, may have communicated among themselves about ways to prevent Mr. Trump’s appointees from undermining the agency’s mission.

Mr. Kerner drew bipartisan praise for defending whistle-blowers in a Senate Homeland Security and Governmental Affairs Committee hearing last week. But his E.P.A. inquiries have raised questions about whether he is genuinely committed to free speech and to enforcing the Hatch Act against top White House officials.

It seems a long shot that Mr. Trump will name an experienced, nonpartisan replacement for Mr. Shaub. But such an appointment would help protect Mr. Trump’s team from legal jeopardy and, not incidentally, help bolster public trust in an administration that so far has earned little.