WASHINGTON — Rod J. Rosenstein, a lifelong Republican with a tough-on-crime record, was eager to put his stamp on the Justice Department when he was sworn in as the deputy attorney general in the early months of the Trump administration.
Instead, he was abruptly thrust into a political maelstrom after President Trump fired James B. Comey as F.B.I. director only two weeks later. Mr. Rosenstein appointed a special counsel to investigate Russia’s election interference and spent the next year and a half defending that inquiry from both Mr. Trump’s unwavering attacks and attempted political intrusion by his congressional allies.
Now Mr. Rosenstein plans to step down as the United States’ No. 2 law enforcement official after Mr. Trump’s nominee for attorney general, William P. Barr, is confirmed, three administration officials said on Wednesday. Senators could vote to confirm him as early as next month.
Mr. Barr will represent a new chapter for the Justice Department and for the Russia investigation, which is nearing its final stages and is expected to be finished in the coming weeks or months, according to senior law enforcement officials. They cautioned that like any investigation, it could be prolonged if the special counsel overseeing the inquiry, Robert S. Mueller III, were to cover uncover new evidence central to his mandate.
Mr. Barr, who met with senators on Capitol Hill on Wednesday ahead of his confirmation hearing next week, holds a dim view of aspects of the investigation but affirmed that he would allow it to conclude, said Senator Lindsey Graham, Republican of South Carolina and the new chairman of the Judiciary Committee.
“He says Bob Mueller is a great guy — ethical, professional,” Mr. Graham said of Mr. Barr in a brief interview. “He believes that he is not on a witch hunt, trusts him to be fair to the president and the country, and has no reason to believe he is not going to do that.”
The timing of Mr. Rosenstein’s anticipated departure was unconnected to the Mueller investigation, a Trump administration official said. Mr. Rosenstein privately told Mr. Barr weeks ago that a term of roughly two years seemed like the right length, according to Mr. Graham.
After Jeff Sessions’s time as attorney general was done, Mr. Rosenstein was supportive of the decision to replace him with Mr. Barr, according to a person who has discussed the issue with Mr. Rosenstein. He and Mr. Barr worked together at the Justice Department during the George Bush administration.
While most deputy attorneys general labor in obscurity, Mr. Rosenstein became a target of criticism from the president and his allies while liberals cheered his efforts to shield the Russia investigation from Mr. Trump’s vitriol. He was given standing ovations at many of his speeches last year and was feted on late-night television. Strangers would ask him for his autograph and for photographs with him at airports and in other public places.
But his record on the Russia investigation was more complicated. In the tumultuous days after the president fired Mr. Comey in May 2017, Mr. Rosenstein was shaken and angry, concerned that the White House had used him to justify the firing, associates have said.
In meetings with senior law enforcement officials, he suggested secretly taping his conversations with Mr. Trump and invoking the 25th Amendment to remove the president from office, according to people familiar with the discussions and a memo written by Andrew McCabe, then the deputy F.B.I. director.
Mr. Rosenstein ultimately sought to stem the chaos by appointing Mr. Mueller as special counsel, but he consulted almost no one, according to three department officials who were not authorized to discuss the appointment.
Later, his work to protect the Mueller investigation from Mr. Trump’s congressional allies, whom Democrats accused of trying to subvert sensitive investigations, also drew criticism. To mollify the lawmakers, Mr. Rosenstein made scores of documents related to those inquiries available, moves that ran counter to law enforcement’s reticence to share information about investigations.
Senior law enforcement officials noted that under Mr. Rosenstein, the department won one of its most critical battles with conservative lawmakers who had sought the declassification of a wiretap application at the heart of the Russia inquiry. Despite congressional Republicans’ urging, the White House declined to release the document.
“Rod was in a truly unusual position and was largely a steady hand,” said Megan L. Brown, a lawyer at the firm Wiley Rein who worked at the Justice Department with Mr. Rosenstein under President George W. Bush.
A graduate of the University of Pennsylvania and Harvard Law School, Mr. Rosenstein had worked at the Justice Department for nearly 30 years before becoming deputy attorney general. Early on, he was a trial lawyer in Washington and later was the United States attorney for Maryland under Mr. Bush and President Barack Obama.
He ascended to his post eager to help Mr. Sessions crack down on violent crime and drug trafficking and became known for the long hours he kept while running the day-to-day work of the Justice Department, sometimes sending emails at 3 a.m., according to two lawyers who worked closely with him.
Inside the department, law enforcement officials said Mr. Rosenstein helped usher in the sort of tough-on-crime policies that he supported during his 12 years as the top federal prosecutor in Maryland. He paid also special attention to the nation’s federal prosecutors, some of whom said they felt neglected during past administrations.
Mr. Rosenstein has been at the forefront of Trump administration efforts to crack down on Chinese spying while also tightening rules and cracking down on department employees who provide information to the news media to inform the public.
He had an uneven relationship with Mr. Trump almost from the start. Though the president blamed Mr. Sessions, who had recused himself from the Russia investigation, for the appointment of a special counsel, Mr. Trump also attacked Mr. Rosenstein repeatedly, calling him “conflicted” in one instance because Mr. Rosenstein had recommended Mr. Comey’s firing but installed Mr. Mueller.
The relationship was tested in September after The New York Times revealed Mr. Rosenstein’s questioning in May 2017 of Mr. Trump’s fitness to be president and offers to secretly record conversations with him. Mr. Rosenstein has denied that account.
Rattled and unsure how the president would react, Mr. Rosenstein considered quitting and even had aides draft a news release about his resignation. But senior White House advisers urged him to stay on, and, over time, he and the president, who meet or speak by telephone frequently, found common ground.
It almost certainly helps that he is no longer the top law enforcement official overseeing the Mueller investigation. After the holidays last month, Mr. Rosenstein and his family visited Mr. Trump at the White House to meet the president and have a photograph taken with him.
His uneasy standing with Mr. Trump is not lost on him. At a conference last month where the president was to appear later, Mr. Rosenstein joked: “You let the president know that his favorite deputy attorney general was here.”
Reporting was contributed by Nicholas Fandos, Adam Goldman, Michael S. Schmidt and Eileen Sullivan.