The ethics watchdog who has badgered the Trump administration for months about conflicts of interest says he is leaving the federal government.

Walter Shaub, director of the previously little-known Office of Government Ethics, made a name for himself by criticizing the administration repeatedly, most notably over Trump's refusal to sell his business interests.

He also took presidential aide Kellyanne Conway to task for plugging Ivanka Trump products in a live TV interview, and he raised doubts about ethics waivers that the White House granted to its own employees.

Shaub said on Twitter that he is taking a job at the Campaign Legal Center, a nonprofit, nonpartisan advocacy group for tougher campaign finance laws. In a statement released by the center, Shaub said he would work on ethics reform at all levels of government.

"In working with the current administration, it has become clear to me that we need improvements to the existing ethics program," he said.

Shaub's resignation is effective July 19.

The White House said in a statement that it "appreciates his service."

"The President will be nominating a successor in short order," the statement said. The ethics director is appointed to a five-year term and needs to be confirmed by the Senate.

Shaub joined the ethics office as a staff attorney early in the George W. Bush administration and has worked there almost every year since. He was appointed as director by President Barack Obama, and his term was supposed to run into 2018.

The ethics office works with executive branch employees to avoid conflicts of interest, though it does not have enforcement power. Before the election, it was mostly unheard of by anyone other than Washington wonks and agency officials.

Related: The little-known ethics director who took on Trump

But the agency raised eyebrows in late November, when its Twitter account sent out a series of unusual tweets that enthusiastically congratulated Trump for divesting himself of his business holdings, even though Trump had made no plans to do so.

Shaub later said he was trying to use Twitter -- Trump's favored way of communicating -- to encourage him to divest.

Trump refused to sell his business holdings as president. Instead, he transferred them into a trust in his name. Any business profits will ultimately accrue to him when he leaves office.

In January, Shaub stunned ethics colleagues by publicly admonishing Trump's decision to not divest his interests. He condemned Trump's plan as "wholly inadequate."

After Shaub spoke out, the ethics office was flooded with media requests. Fans created T-shirts and Facebook pages in celebration. And critics decried the decision as a politically motivated act by a man who had once donated to Obama's re-election campaign.

The ethics office and the White House kept trading barbs. Shaub in February asked the White House to discipline Conway after she told Fox News viewers to "Go buy Ivanka's stuff" during an interview.

Federal rules prohibit executive branch employees from endorsing products.

The White House, however, said Conway was acting "without nefarious motive" and deserved no punishment. Shaub shot back, saying that not taking action "risks undermining the ethics program."

Shaub's office also tussled with the White House over the release of ethics waivers the administration had given its staff. The battle dragged on for more than a month before the administration released its waivers in June.

But tensions between the two sides remained. After Shaub called one of the waivers "problematic" because it was not signed or dated, the White House fired back: "The Office of Government Ethics needn't be concerned with how the White House implements its own conflicts of interest policy, over which it has zero authority."

Related: Ethics watchdog says White House lawyer might have broken rules

And as recently as last week, Shaub was still raising concerns. After Democratic lawmakers contacted him about whether a White House ethics lawyer violated the office's conflict of interest rules, Shaub asked the administration to look into the matter.

That inquiry was again met with disdain. The White House accused Shaub and the Democrats of "distorting facts and attempting to tarnish the White House for purposes of a partisan agenda."

Shaub said that an ethics office review of White House ethics waivers will continue after his departure.