U.S. Deputy Attorney General Rod J. Rosenstein on Wednesday cautioned current and former federal judges and prosecutors in Washington against allowing political passions to shape overzealous prosecutions.

The comments came in a speech extolling the rule of law as Rosenstein, who holds the No. 2 position in the Justice Department, spoke at the federal courthouse overseeing special counsel Robert S. Mueller III's grand jury probe into whether President Trump's campaign coordinated with Russia to influence the 2016 election.

The appearance by Rosenstein, who appointed Mueller in May and has authority over the investigation, was planned months ago. He gave a substantially similar speech six weeks ago at the conservative Heritage Foundation.

But his timing, two days after the investigation's first criminal charges were unsealed, and his audience — lawyers and the judges predominantly appointed by Democratic presidents, including those handling cases brought by Mueller's prosecutors — lent a political subtext, whether intended or not.

Rosenstein took questions, but the audience was told not to ask about the Russia investigation because he could not discuss it.

Rosenstein said one of his most important duties was to "safeguard the integrity of the Department of Justice and to uphold the rule of law," and noted the president's constitutional responsibility to "take care that the laws be faithfully executed."

He reminded the public of its responsibility to uphold democratic institutions, recalling Benjamin Franklin's purported answer to a woman who asked what kind of government the Continental Congress had chosen: "A republic — if you can keep it."

But he mostly emphasized prosecutors' duty not to rush to judgment, citing former Franklin D. Roosevelt attorney general and Supreme Court justice Robert Jackson's admonition that although violations of the law abound, prosecutors ought to charge only those "in which the offense is the most flagrant, the public harm the greatest, and the proof the most certain."

Repeating Abraham Lincoln's warning in 1838 after a mob in Illinois lynched an African American man suspected of murder, Rosenstein said, "When men take it in their heads today to hang gamblers or burn murderers, they should recollect that in the confusion usually attending such transactions they will be as likely to hang or burn someone who is neither a gambler nor a murderer as one who is."

He concluded, "And that acting upon the example they set, the mob of tomorrow may, and probably will, hang or burn some of them by the very same mistake."

[Special counsel is investigating Trump for possible obstruction of justice, officials say]

Attorney General Jeff Sessions recused himself from the Trump-Russia case because of his role in the Trump campaign, leaving Rosenstein with the authority to approve Mueller's budget, remove him from his post or veto any investigative step with congressional notification.

Mueller's team interviewed Rosenstein this year about Trump's removal of James B. Comey as FBI director, investigating whether the president might have attempted to obstruct justice leading up to Comey's firing.

[Trump said he was thinking of Russia controversy when he decided to fire Comey]

Rosenstein wrote a memo highly critical of the FBI director, which the White House used initially to explain the firing, before Trump later tweeted that he was going to fire Comey regardless.

It was not clear whether Rosenstein had the episode in mind when he reminded the Wednesday audience of a saying by author Richard Bach, "Live never to be ashamed if anything you do or say is published around the world — even if what is published is not true." After a pause, Rosenstein added, "And I have some recent experience with that riddle."

Rosenstein spoke in the federal courthouse's Ceremonial Courtroom at the annual Judge Thomas A. Flannery Lecture Series, named after the late judge and former U.S. attorney for the District who served 30 years at the federal courthouse.

Rosenstein has deep ties to the courthouse. Rosenstein, who was U.S. attorney for Maryland from 2005 to 2012, joined the Justice Department in 1990 after clerking for Judge Douglas H. Ginsberg at the U.S. Court of Appeals for the D.C. Circuit.