By MICHAEL D. SHEAR, KATIE BENNER, MAGGIE HABERMAN and MICHAEL S. SCHMIDT, New York Times–

When Rod J. Rosenstein, the deputy attorney general, headed to the White House on Monday morning, he was ready to resign and convinced — wrongly, it turned out — that President Trump was about to fire him. Top Justice Department aides scrambled to draft a statement about who would succeed him.

By the afternoon, Mr. Rosenstein was back at his Pennsylvania Avenue office seven blocks from the White House, still employed as the second-in-command at the Justice Department and, for the time being at least, still in charge of the Russia investigation.

What happened in between was a confusing drama in which buzzy news reports of Mr. Rosenstein’s imminent departure set in motion a dash to the White House, an offer to resign, Capitol Hill speculation about Mr. Rosenstein’s successor and, finally, a reprieve from an out-of-town president.

“We’ll be determining what’s going on,” Mr. Trump said Monday afternoon from New York, where he was meeting with foreign leaders at the United Nations General Assembly. Asked about Mr. Rosenstein, Mr. Trump said: “We’re going to have a meeting on Thursday when I get back.”

Even for an administration famous for chaos and rival factions, Monday’s events offered a remarkable display of the anxiety gripping the administration after a New York Times report on Friday that Mr. Rosenstein had considered secretly taping the president and discussed using the 25th Amendment to remove him from office.

Mr. Rosenstein called the account “inaccurate.” But it raised fresh questions about the fate of the deputy attorney general, who has repeatedly clashed with Mr. Trump and his supporters on Capitol Hill over the Russia inquiry. Critics called for him to be fired. Allies demanded he stay.

This account of the events of the past several days is based on interviews with people close to Mr. Rosenstein, White House advisers, Justice Department officials, lawmakers from both parties and others familiar with the rapidly evolving situation.

By Friday evening, concerned about testifying to Congress over the revelations that he discussed wearing a wire to the Oval Office and invoking the constitutional trigger to remove Mr. Trump from office, Mr. Rosenstein had become convinced that he should resign, according to people close to him. He offered during a late-day visit to the White House to quit, according to one person familiar with the encounter, but John F. Kelly, the White House chief of staff, demurred.

Aides began planning over the weekend for his departure, coming in to the Justice Department to determine how to recalibrate in the aftermath of his exit.

Over the weekend, Mr. Rosenstein again told Mr. Kelly that he was considering resigning. On Sunday, Mr. Rosenstein repeated the assertion in a call with Donald F. McGahn II, the White House counsel. Mr. McGahn, who was dealing with the emergence of another accusation of sexual assault against Brett M. Kavanaugh, the president’s Supreme Court nominee, asked Mr. Rosenstein to postpone their discussion until Monday.

Some White House officials also believed that only the president could legally accept Mr. Rosenstein’s resignation, not Mr. Kelly, according to two people familiar with internal discussions.

By about 9 a.m. on Monday, Mr. Rosenstein was in his office on the fourth floor of the Justice Department when reporters started calling. Was it true that Mr. Rosenstein was planning to resign, they asked? Officials at the Justice Department took the inquiries as evidence that the White House wanted to speed along that outcome.

Mr. Rosenstein and Ed O’Callaghan, his top deputy, raced out of the building and headed to 1600 Pennsylvania Avenue for what they expected to be the final word. Justice Department officials told reporters that Mr. Rosenstein expected to be fired upon arriving there.

A spokeswoman, Sarah Isgur Flores, began drafting a news release that Attorney General Jeff Sessions, who was on his way back from a weekend in Alabama, would distribute if Mr. Rosenstein were fired.

At the White House, the deputy attorney general slipped into a side entrance to the West Wing and headed to the White House Counsel’s Office to meet with Mr. McGahn, who had by then been told by Mr. Kelly that Mr. Rosenstein was on his way and wanted to resign.

Mr. Rosenstein was emotional, according to people familiar with his meeting with Mr. McGahn. Mr. Rosenstein wanted to leave on amicable terms, not in a manner that would trigger an angry Twitter tirade from Mr. Trump.

But Mr. McGahn, who is set to leave the White House as soon as the Kavanaugh nomination is concluded, reminded Mr. Rosenstein of his own short-term status and directed him to talk to Mr. Kelly.

Two people familiar with the discussions described Mr. Kelly as “conflicted” about Mr. Rosenstein’s fate, believing that a departure before the midterm elections in November would be bad for the president. At some point, Mr. Rosenstein and Mr. Trump had what the president’s spokeswoman called “an extended conversation” about the Times article. Mr. Trump said the two spoke Monday but did not say when.

The president had already planned to clean house at the Justice Department — but not until after the elections, according to one person who had discussed Mr. Rosenstein with Mr. Trump before last week’s Times article. Monday’s drama about an imminent resignation created an unwanted headache, the person said.

a group of people walking down the street: A television reporter on Monday outside the White House.© T.J. Kirkpatrick for The New York Times A television reporter on Monday outside the White House.But as Mr. Rosenstein and Mr. Kelly remained behind closed doors, the possibility of Mr. Rosenstein’s departure had already sparked blaring headlines about the implications for the Russia probe and the management of the Justice Department.

“Rod Rosenstein, Deputy Attorney General, Is Considering Resigning,” The Times wrote. CNN and MSNBC broke into their coverage of the confirmation battle over Judge Kavanaugh to report that Mr. Rosenstein was on his way to the White House to resign.

On Capitol Hill, lawmakers were caught off guard. Some legislators from both parties, already wrangling over the Kavanaugh nomination and girding for November’s elections, seemed to wish the matter would simply disappear.

“I hope they can work it out,” said Senator John Cornyn of Texas, the No. 2 Senate Republican. He told reporters that Mr. Rosenstein had done “a good job in a tough position” and, echoing a line senators have repeatedly employed to try to dissuade Mr. Trump from shaking up senior law enforcement, warned that confirming a replacement for Mr. Rosenstein at this point would be “problematic.”

Senator Susan Collins, Republican of Maine, expressed more consternation, saying on Twitter that she was “concerned” by reports of Mr. Rosenstein’s fate and that he “plays a critical role” overseeing the Russia inquiry.

On his radio show on Monday, the president’s personal lawyer, Jay Sekulow, said he did not know whether Mr. Rosenstein was going to be pushed out. But he used the confusion to call for a pause in the Russia investigation, saying that if Mr. Rosenstein did resign, it “clearly becomes necessary and appropriate” that “there be a step back taken here” and a “time out on this inquiry.”

Word began leaking out of the White House that Mr. Rosenstein had joined a previously scheduled meeting of top administration officials in the West Wing — evidence that he had not resigned or been fired. At the Justice Department, Mr. Sessions returned around the time it became clear that Mr. Rosenstein was not being fired.

Speculation continued until 12:48 p.m., when Sarah Huckabee Sanders, the White House press secretary, tweeted that Mr. Rosenstein had requested a conversation with the president.

“Because the President is at the United Nations General Assembly and has a full schedule with leaders from around the world, they will meet on Thursday when the President returns to Washington,” Ms. Sanders said.

Within the hour, Mr. Rosenstein exited the White House, captured by news cameras being escorted to his black SUV by Mr. Kelly. The motorcade swiftly drove back to the Justice Department, where the deputy attorney general went back to his scheduled meetings, including one on white-collar crime, and other law enforcement officials turned back to preparing for Tuesday’s meeting between Mr. Sessions and state attorneys general about tech companies.

The release that Ms. Flores drafted did not go out.

But the fact that Mr. Rosenstein may be on the job for at least another 72 hours is unlikely to be the end of the story. A departure by Mr. Rosenstein this week would thrust the administration into further turmoil just weeks before November’s midterm elections.

As the top Justice Department official overseeing the investigation by Robert S. Mueller III, the special counsel, Mr. Rosenstein had long been the target of Mr. Trump’s bitter grievance about what he calls a politically motivated witch hunt. Mr. Rosenstein has repeatedly backed Mr. Mueller.

Though officials have said their relationship had improved recently, the president was said to consider terminating Mr. Rosenstein in summer 2017. More recently, in a Twitter rant in April, Mr. Trump accused Mr. Rosenstein of being one of the most conflicted officials at the Justice Department, asserting without evidence that he was among those seeking proof of a Trump-led conspiracy with Russia’s election interference.

“No Collusion, so they go crazy!” Mr. Trump wrote.

If Mr. Rosenstein leaves, Noel Francisco, the solicitor general, would assume oversight of the Russia investigation, according to a Justice Department official. Matthew G. Whitaker, chief of staff to Mr. Sessions, would become acting deputy attorney general, an unusual move; typically, a top aide to the deputy attorney general would take over the post.

Critics have said that Mr. Francisco cannot oversee the Russia investigation without a waiver from the White House because his former law firm, Jones Day, is representing the Trump campaign in the investigation, creating a conflict of interest. Justice Department officials have not addressed whether a waiver would be needed if Mr. Rosenstein departs.

Republican lawmakers aligned with Mr. Trump have spent months wrangling over information pertaining to Justice Department investigations. Democratic opponents have said that those increasing demands were meant to corner Mr. Rosenstein and eventually push him to either compromise the integrity of the investigations or to resign.

On Monday, Representative Bob Goodlatte, Republican of Virginia and the chairman of the House Judiciary Committee, appeared to validate Mr. Rosenstein’s concerns about being called to testify about the Times article. It was based on interviews over several months with people who were told about Mr. Rosensteins’ comments at the time or who were briefed on memos that documented them, including some written by Andrew G. McCabe, the acting director of the F.B.I. at the time.

Mr. Goodlatte said that he planned to issue a subpoena for Mr. McCabe’s memos as soon as this week. House Republicans close to Mr. Trump had already made one attempt to obtain copies of the memos but were rebuffed by the Justice Department.