The White House promptly accepted Mr. Shaub’s resignation, and Lindsay E. Walters, a White House spokeswoman, said in a statement that the administration “appreciates his service.” Mr. Trump, she said, would nominate a successor “in short order.”
By departing ahead of schedule, Mr. Shaub handed Mr. Trump an opportunity to begin putting his mark on the agency overseeing the federal government’s vast ethics program, including that of the White House. The office’s director has traditionally had wide latitude to set its priorities, its tone in working with the White House and other federal agencies, and, perhaps most important, how to interpret the country’s ethics laws.
The vacancy is all but certain to frighten Democrats and those in the small world of government ethics who see the office under Mr. Shaub as an important political bulwark against conflicts of interest in the upper echelons of the government. To Mr. Trump’s defenders, who have seen Mr. Shaub, an Obama appointee, as politically motivated, it is more welcome news.
The intensity of feeling over what is usually an obscure job speaks to the central role ethics have come to play in Mr. Trump’s Washington, where the vast holdings of the president and his cabinet, as well as an influx of advisers from businesses and lobbying firms, have raised a rash of accusations of conflicts of interest.
It is the job of the ethics office, a creation of a post-Watergate Congress, to work with a web of ethics officials at each agency to help people entering the government sidestep potential conflicts. The office guides each administration’s political appointees through financial disclosure requirements and creates agreements to restrict participation in deliberations over topics they handled for paying clients.
Mr. Shaub, 46, had faced an uncertain future at the agency since Mr. Trump took office in January. In the weeks between the president’s unexpected election victory and his inauguration, Mr. Shaub took an extraordinary gamble: He recommended very publicly on Twitter, and in a rare public speech, that Mr. Trump liquidate his vast business and personal holdings. This arrangement, Mr. Shaub argued, was the only truly ethical option.
Mr. Trump did not heed his advice, and by the middle of January, Mr. Shaub thought he might be fired. To minimize his attachment to the position, he packed up the personal possessions that filled his office.
But he was not fired, even as he continued to spar with Mr. Trump’s aides over a range of ethical concerns, including the ethics office’s authority to exercise oversight of the White House.
In February, he recommended that the White House discipline Kellyanne Conway, a top adviser to the president, after she made an on-air endorsement of the clothing line of Ivanka Trump, the president’s daughter. The White House Counsel’s Office disagreed and took no disciplinary action.
More recently, Mr. Shaub and the administration fought over a routine request by the ethics office for copies of waivers issued to White House appointees to work in the Trump administration. The Office of Management and Budget initially balked at the request, challenging Mr. Shaub’s legal authority even to ask for the information and asking him to withdraw it. After Mr. Shaub fired back with a stern 10-page letter rebutting the argument, the White House backed down.
The White House eventually released the waivers, which showed that it had granted at least a dozen exemptions for aides to work on policy matters they had handled as lobbyists or to engage with former colleagues in private-sector jobs. Mr. Shaub objected to the fact that many of the waivers were undated and unsigned, and that some approved actions retroactively.
Mr. Shaub, who served for about a decade as a career civil servant at the agency before being appointed director, said his role had always been politically neutral. He says he has not been fighting Mr. Trump, as some critics have suggested, but that, rather, his decisions to speak out have been motivated by a desire to defend an ethics program that has traditionally counted on support from Democrats and Republicans alike. He said he spoke publicly only after more traditional channels were exhausted.
Mr. Shaub has continued to make a case for his line of reasoning. In an interview on Thursday with CBS News, he said Mr. Trump’s decision not to liquidate his assets meant there was now “an appearance” that his businesses were profiting from the presidency.
“You can’t be sure,” Mr. Shaub said. “America should have the right to know what the motivations of its leaders are, and they need to know that financial interests — personal financial interests — aren’t among them.”
Mr. Shaub will leave the agency this month to take up his new position as a senior director for ethics at the Campaign Legal Center in Washington, a nonpartisan group that advocates campaign finance reform and litigates voting rights cases. There, he will have more freedom to comment on the government’s ethics program and to propose a set of changes he said were needed badly.
News of Mr. Shaub’s departure was greeted on Thursday with more acquiescence than surprise. Those who have worked in the ethics office or in the White House said it raised pressing questions over whether Mr. Trump’s choice of Mr. Shaub’s successor would quiet the agency’s criticism.
“I don’t think anyone who comes after Walter is going to challenge the White House publicly the way that I think he did,” said Richard W. Painter, who served as ethics counsel for the George W. Bush White House. “It is a great loss.”
Mr. Painter said the administration would do itself a favor by naming a successor with experience in ethics law and a reputation for independence.
A permanent replacement for Mr. Shaub would require confirmation in the Senate, where Democrats would probably use confirmation hearings to raise grievances about what they see as Mr. Trump’s potential conflicts of interest, and Republicans are unlikely to act as a rubber stamp.
The White House could also elect to leave the position to an acting director indefinitely. Shelley K. Finlayson, the office’s chief of staff, is first in line for the acting director position, but the law governing such vacancies also allows the White House to choose from among the office’s upper ranks.
That arrangement, experts said, could help preserve the office and allow it to go about much of its work. Or it could simply be a quieter way to neutralize it, said Marilyn L. Glynn, who served as the agency’s acting director during the Bush administration.
“Based on my experience as acting director, you clearly don’t have the visibility and power that a full director would have,” Ms. Glynn said. “That is one way of keeping the office fully below the radar.”