Deputy Attorney General Rod J. Rosenstein — whose tumultuous two years as the No. 2 Justice Department official were marked by battles over the special-counsel probe of President Trump — submitted a resignation letter Monday indicating he will leave the job in two weeks.

Rosenstein’s departure had been expected since the beginning of the year, but the date was repeatedly pushed back as special counsel Robert S. Mueller III wound down his investigation and compiled a report detailing his findings.

Since his first days on the job, Rosenstein’s role in the Trump administration was controversial, from the firing of FBI Director James B. Comey in May 2017 to the conclusion by Rosenstein and Attorney General William P. Barr that there was not sufficient evidence for an obstruction-of-justice case against the president.

Republican senators spoke to reporters on Jan. 9 about the news that Deputy Attorney General Rod J. Rosenstein may leave the Justice Department. (Rhonda Colvin, Jorge Ribas/The Washington Post)

In his resignation letter to Trump, Rosenstein praised the president for his personal charm and policy goals. “As I submit my resignation effective on May 11, I am grateful to you for the opportunity to serve; for the courtesy and humor you often display in our personal conversations; and for the goals you set in your inaugural address: patriotism, unity, safety, education, and prosperity, because ‘a nation exists to serve its citizens,’ ” Rosenstein wrote.

He ended his letter with a sentence that asserted the Justice Department’s independence, before closing with a phrase from Trump’s campaign: “We keep the faith, we follow the rules, and we always put America first.”

The resignation letter was first reported by the Wall Street Journal.

The new attorney general praised Rosenstein’s long career in federal law enforcement.

“Over the course of his distinguished government career, he has navigated many challenging situations with strength, grace, and good humor,” Barr said in a statement. “Rod has been an invaluable partner to me during my return to the Department, and I have relied heavily on his leadership and judgment over the past several months.”

Earlier this year, Trump nominated Rosenstein’s replacement, Deputy Transportation Secretary Jeffrey Rosen, who still must be confirmed by the Senate. The Judiciary Committee said Monday it will consider Rosen’s nomination on Thursday, which means he could be confirmed by early May.

Rosenstein’s resignation letter comes days after The Washington Post reported that he had assured Trump in a call last year that he was on his team and that the special counsel’s investigation would treat the president fairly.

The September conversation, according to people familiar with it, followed an explosive New York Times report that Rosenstein had suggested wearing a wire to surreptitiously monitor the president, or using the 25th Amendment to oust him from office — reporting that Rosenstein disputes.

“I give the investigation credibility,” Rosenstein told Trump, according to an administration official with knowledge of what was said during the call. “I can land the plane.”

While it is difficult to interpret Rosenstein’s remarks, he was apparently trying to mollify Trump and save his own job, or at least his reputation.

“I can go. I’m ready to go. I can resign. But I don’t want to go out with a tweet,” the deputy attorney general said in a meeting with Trump’s chief of staff before the call, according to one person’s account. Trump routinely makes significant personnel announcements via Twitter.

In his resignation letter, Rosenstein extolled the Justice Department’s accomplishments during the Trump administration.

“We enforce the law without fear or favor because credible evidence is not partisan, and truth is not determined by opinion polls,” Rosenstein wrote. “We ignore fleeting distractions and focus our attention on the things that matter, because a republic that endures is not governed by the news cycle.”

He also defended the department’s handling of the Russia probe, writing that the country “is safer, our elections are more secure, and our citizens are better informed about covert foreign influence efforts.” Rosenstein went on to cite the kinds of cases in which the president has expressed a personal interest. “We also pursued illegal leaks, investigated credible allegations of employee misconduct, and accommodated congressional oversight without compromising law enforcement interests,” he wrote.

Matthew Miller, a Justice Department spokesman in the Obama administration, said he found particularly odd the “over-the-top praise for the president who has spent his entire tenure attacking the Department of Justice. . . . When one of the most consistent themes of the president’s tenure has been attacking the career men and women at the Department of Justice, it’s just inappropriate for a deputy attorney general to heap all of this unalloyed praise on him.”

On Thursday, in one of his last public speeches as the deputy attorney general, Rosenstein lashed out at politicians and the media, denouncing what he called “mercenary critics who get paid to express passionate opinions about any topic, often with little or no information. . . . They make threats, spread fake stories and even attack your relatives.”

In recent weeks, Rosenstein has faced criticism for how the Justice Department released the findings of Mueller’s investigation. Rosenstein signed on to Barr’s conclusion — which went further than Mueller had been willing to go — that there was insufficient evidence to accuse Trump of obstructing justice, and he stood behind Barr when the attorney general repeatedly declared at a news conference that Mueller had concluded there was no collusion between the Trump campaign and Russia.

Democrats and legal analysts have asserted that Barr was casting Mueller’s report in a way that was overly favorable to Trump, with public support from Rosenstein.

Rosenstein was long viewed as one of the last bastions insulating the Mueller probe from political interference. But Rosenstein’s role was always deeply controversial, since it was a memo he wrote criticizing Comey that formed the public justification for firing him as FBI director — a move that led Rosenstein, days later, to appoint Mueller as special counsel to carry on the Russia investigation.