Rachel L. Brand, the third-highest-ranking official at the Justice Department and the first woman to serve as associate attorney general, plans to step down, the department announced Friday — a resignation that comes at a moment of intense political scrutiny for the department, including some harsh criticism from President Trump.

Brand, 44, who has been in her Senate-confirmed position for only nine months, would have been in line to take over the supervision of special counsel Robert S. Mueller III’s Russia investigation if Deputy Attorney General Rod J. Rosenstein, the department’s No. 2 official, was fired by Trump or recused himself from the matter.

Brand is leaving the Justice Department to join Walmart as the executive vice president for global governance, the company said. Her departure was first reported by the New York Times.

The possibility of Brand being thrust into the Russia investigation has increased in recent weeks as Rosenstein has come under political attack from Republicans for supporting the renewal of a surveillance warrant on a former Trump campaign adviser.

“I think it’s a disgrace what’s happening in our country,” Trump said last week when he was asked about the release of a memo from Republicans on the House Intelligence Committee claiming abuses in the Russia investigation.

“A lot of people should be ashamed of themselves and much worse than that,” Trump said.

When Trump was asked by a reporter whether he was then more likely to fire Rosenstein and whether he had confidence in him, Trump replied, “You figure that one out.”

Trump has also publicly attacked the FBI, which is a component of the Justice Department. He has blasted Attorney General Jeff Sessions for recusing himself in the Russia investigation and turning it over to Rosenstein, who then appointed Mueller as special counsel. He said he wouldn’t have appointed Sessions if he knew he was going to recuse himself from the Russia probe.

Last summer on Twitter, Trump called Sessions “beleaguered” and “very weak,” and at a news conference in the Rose Garden said he was “disappointed in Sessions.”

With Brand’s departure, Solicitor General Noel Francisco is next in line at the Justice Department to oversee the Russia investigation after Rosenstein.

“Rachel has shown real leadership over many important divisions at the Department,” Sessions said in a statement. “I know the entire Department of Justice will miss her, but we join together in congratulating her on this new opportunity in the private sector.”

Brand in a statement thanked Sessions for his leadership and said, “I’ve seen firsthand his commitment to the rule of law and to keeping the American people safe.”

Brand has kept a low profile at the department, but in December she wrote an op-ed in The Washington Post defending the renewal of Section 702 of the Foreign Intelligence Surveillance Act, which permits the National Security Agency to collect foreign intelligence on U.S. soil without individualized warrants.

“To keep us safe, our intelligence agencies must be able to “connect the dots” between the various pieces of information the government already lawfully possesses,” Brand wrote. “In reauthorizing Section 702, Congress must not forget the lessons we learned from 9/11.” The law was reauthorized in January.

Last week, Brand headed up an all-day summit on human trafficking at the department, where she told a packed room that “combating this evil is one of our top priorities at the Justice Department.” She also introduced Sessions, who in turn praised Brand for her “strong leadership as our third in command at the department.”

The news that Brand is leaving came as a surprise to many people who know her. The Federalist Society just announced Friday that Brand is scheduled to speak next week at a Washington chapter lunch.

The daughter and granddaughter of Dutch dairy farmers in Iowa, Brand has been praised for her deep knowledge of the Justice Department. She was previously President George W. Bush’s assistant attorney general for the Office of Legal Policy, which develops and implements the department’s significant policy initiatives.

Brand has one of the department’s more politically challenging jobs, managing the lawyers who litigate civil issues, including Trump’s travel ban as well as civil rights, environmental and antitrust cases.

Shane Harris, Ellen Nakashima and Matt Zapotosky contributed to this report.