WASHINGTON — Rod J. Rosenstein, the deputy attorney general, said Monday that he would leave the Justice Department in mid-May, bringing to a close a turbulent two-year tenure that was overshadowed by the special counsel’s investigation into Russia’s efforts to sway the 2016 election in favor of President Trump.
“As I submit my resignation effective on May 11, I am grateful to you for the opportunity to serve,” Mr. Rosenstein wrote in a resignation letter to Mr. Trump. Despite a stormy relationship with the president, he praised Mr. Trump in the letter, thanking him for “the courtesy and humor” he displayed in their conversations together and for championing “patriotism, unity, safety, education and prosperity” in his inaugural address.
Department officials close to Mr. Rosenstein had previously signaled that he would leave after the completion of the report by the special counsel, Robert S. Mueller III, which was made public this month. The investigation had thrust him into a political maelstrom, challenging his reputation as a principled Republican lawyer with a distaste for politics that had been honed over 30 years as a federal prosecutor and United States attorney.
He responded by trying to thread a needle, striving to preserve the rule of law and protect one of the department’s most important investigations while publicly praising a president who he knew was determined to undermine both. It meant Mr. Rosenstein often disappointed critics on the left and the right.
The balancing act began almost immediately after Mr. Rosenstein’s confirmation as the No. 2 Justice Department official in April 2017. Two weeks later, Mr. Trump used a memo written by Mr. Rosenstein as a pretext to abruptly fire James B. Comey, the director of the F.B.I., a decision that privately upset Mr. Rosenstein because it was not true. When the president asked Mr. Rosenstein to publicly take responsibility for Mr. Comey’s firing, he declined and told Mr. Trump that he would not lie.
Amid public outrage over the firing, Mr. Rosenstein appointed Mr. Mueller to take over the F.B.I.’s investigation into whether Russia interfered in the 2016 presidential election and what part any members of the Trump campaign may have played in those efforts, as well as whether the president tried to obstruct the investigation.
He then oversaw Mr. Mueller’s work because Jeff Sessions, a former Trump campaign adviser and the attorney general at the time, had recused himself from all campaign-related inquiries.
He did not use his oversight of the special counsel’s office to veto Mr. Mueller’s investigative requests or suppress his work, which he knew the president would have wanted. But throughout the investigation, and Mr. Trump’s efforts to end the inquiry and attack the department, he publicly praised the president as a defender of the rule of law.
His job was at times threatened as the Russia investigation drew closer to Mr. Trump’s inner circle and the president worked publicly and privately to undermine the department and its officials. And he was nearly fired in September, after The New York Times revealed that he had discussed the possibility of removing Mr. Trump from office and wearing a wire into meetings with the president.
But Mr. Rosenstein managed to get back into Mr. Trump’s good graces and see the special counsel’s investigation through to the end.
Mr. Mueller ultimately concluded that Russia interfered in the election to help Mr. Trump win, but that while the Trump campaign “expected it would benefit electorally from information stolen and released through Russian efforts,” it had not conspired with the Russian government.
Mr. Mueller also laid out several instances where Mr. Trump attempted to derail the investigation, but he ultimately allowed department officials to decide whether those amounted to obstruction of justice. Mr. Rosenstein and Attorney General William P. Barr said they did not believe there was enough evidence to bring those charges.
Mr. Rosenstein “has navigated many challenging situations with strength, grace and good humor,” Mr. Barr said in a statement Monday. “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.”
Mr. Trump had already nominated Jeffrey A. Rosen, the current deputy transportation secretary, to replace Mr. Rosenstein. With a Republican majority in the Senate, Mr. Rosen is expected to be confirmed next month with little trouble.
Officials had indicated that Mr. Rosenstein would leave the department in March, when they also expected the Mueller investigation to end. But Mr. Mueller and his team did not submit their final report to the department until March 22, and a redacted version was not made public until this month, delaying Mr. Rosenstein’s departure.