WASHINGTON—Attorney General Jeff Sessions has urged the White House not to fire his deputy, Rod Rosenstein, adding that he would consider resigning himself if President Donald Trump moved to do so.

The warning was conveyed to White House counsel Don McGahn in recent days, with Mr. Sessions communicating strongly that pushing out Mr. Rosenstein would be a bad idea, said a person familiar with the message to Mr. McGahn.

Mr. Sessions’ warning was first reported by The Washington Post on Friday. The White House didn’t immediately respond to a request for comment. The Justice Department declined to comment.

Mr. Rosenstein faced criticism last week from the president and his allies, after FBI agents raided properties tied to Michael Cohen, Mr. Trump’s longtime lawyer, as part of a referral from special counsel Robert Mueller’s investigation into alleged Russian meddling in the 2016 presidential election. Mr. Rosenstein personally approved the raids, according to a person familiar with the matter.

The prospect of Mr. Trump firing the deputy attorney general raised questions about who at the Justice Department would assume supervision of Mr. Mueller if that happened, and whether Mr. Trump would be seen as attempting to impede an investigation he has dubbed an unmerited “witch hunt.”

Democrats raised those concerns publicly, while behind the scenes, some supporters of the administration urged Mr. Trump not to dismiss Mr. Rosenstein or any other senior Justice Department officials, warning of serious political consequences.

Russia denies interference in the 2016 election. Mr. Trump has at times concurred with assessments that there was meddling and at other times disputed them, but he has consistently said his campaign didn’t collude with Russia in any electoral interference.

On Wednesday, Mr. Trump, in response to a reporter’s question, addressed speculation about whether he might fire Messrs. Rosenstein or Mueller.

“As far as the two gentlemen you told me about, they’ve been saying I’m going to get rid of them for the last three months, four months, five months. And they’re still here,” Mr. Trump said. “So we want to get the investigation over with, done with, put it behind us.” He made the comments at a press conference in Florida, where he is spending the week.

Mr. Sessions’s call to the White House counsel came amid tensions between the president and his Justice Department. The week before the attorney general’s call, the Federal Bureau of Investigation had conducted its raids on Mr. Cohen’s properties, prompting the president to attack the investigation publicly and privately.

That reaction raised concerns among people close to the president that he might move to dismiss Messrs. Mueller or Rosenstein, the top two officials overseeing the Russia investigation. The raids were carried out by the Manhattan U.S. attorney’s office, which has been working in coordination with Mr. Mueller’s office.

In a meeting last week at the White House, Mr. Rosenstein told Mr. Trump that the president wasn’t considered a target of the Russia investigation or the probe into Mr. Cohen, according to a person familiar with the matter. That doesn’t mean prosecutors have concluded their investigation, but that they currently don’t have sufficient evidence tying Mr. Trump to a crime.

Mr. Sessions himself has been a focus of Mr. Trump’s criticism for months. The president has strongly criticized his attorney general’s decision to recuse himself from the Russia investigation last spring, and has suggested that he would not have appointed Mr. Sessions to run the Justice Department if he had known he would do so.

Advisers have also warned Mr. Trump against firing the attorney general, saying any such move could prolong the Russia investigation, which Mr. Trump is eager to see come to a swift conclusion.