On William P. Barr’s first full day as attorney general, President Trump singled him out during remarks in the Rose Garden after signing a national emergency declaration aimed at building his long-promised border wall.

“I want to wish our attorney general great luck and speed, and enjoy your life. Bill, good luck,” Trump told him at Friday’s ceremony, drawing light laughter from others in attendance, who surely remembered the many ways the president tormented Barr’s predecessor, Jeff Sessions.

In the days that followed, Trump sent more than a dozen messages to his 58 million Twitter followers reviving his critiques of the Justice Department, which Barr now helms, or the officials who came before him. The president called the Russia investigation a “witch hunt” that is “totally conflicted, illegal and rigged!” He assailed former acting FBI director Andrew McCabe as “disgraced.” And he said McCabe’s claim that Deputy Attorney General Rod J. Rosenstein broached the idea of using the 25th Amendment to oust Trump amounted to treason — while quoting a Fox News Channel pundit describing it as a “coup” attempt.

McCabe “and Rod Rosenstein, who was hired by Jeff Sessions (another beauty), look like they were planning a very illegal act, and got caught,” Trump tweeted Monday. “ . . . This was the illegal and treasonous ‘insurance policy’ in full action!”

Although Trump’s animosity was not aimed at Barr — in fact, he has praised him — it nonetheless puts the attorney general in a particularly awkward position as he begins his job.

Barr, people who know him say, is laboring to maintain his reputation as a relatively independent and principled leader while simultaneously reacting to pressure from his boss, who demands loyalty from his appointees and nominees and frequently disparages the Justice Department as it investigates his campaign and conduct.

“William Barr has been attorney general before, but no attorney general in our history — literally — has been under a president who has such contempt for the rule of law, the judicial process and law enforcement generally,” said Sen. Richard Blumenthal (D-Conn.), a member of the Senate Judiciary Committee. “It’s: ‘Buckle in, because it’s going to be a wild ride, Mr. Barr. You ain’t seen nothing yet.’ ”

So far, Barr has kept a low profile, spending most of his time getting up to speed on how the department he led more than 25 years ago, in the George H.W. Bush administration, operates today.

He has not publicly addressed Trump’s running commentary of the past few days. But soon after he was confirmed by the Senate last week, he wrote in a memo to Justice Department employees that times have changed not just in the threats that federal law enforcement has to respond to, but in the microscope the department is now under.

“Advances in technology have given rise to new threats but also new tools to meet those threats, as well as new opportunities,” Barr wrote. “And the Department has faced ever-increasing scrutiny from all quarters as news cycles have shrunk from days, to hours, to nanoseconds.”

The memo’s only reference to Trump was Barr expressing gratitude “to the President for his confidence in me and for the opportunity to lead the Department and to serve the Nation once again.”

On Tuesday, Barr invited Justice Department employees to stop by his office for an open house of sorts, and aides said he paid for refreshments out of his own pocket. Some department employees said Barr’s confirmation had buoyed spirits, which had sunk after Trump asked Sessions to resign and replaced him with Matthew G. Whitaker, whose qualifications to be acting attorney general were doubted by some in the building.

Whitaker remains at the Justice Department as a senior counselor in the associate attorney general’s office, though it is expected that he will depart soon, people familiar with the matter said.

“It’s a new day over here,” said one Justice Department official who was not authorized to talk on the record and so spoke on the condition of anonymity.

Barr is viewed internally as a “lawyer’s lawyer,” the official said, and is seen as less politically minded than Sessions or Whitaker. He is well respected in the department as well as in conservative legal circles, having worked extensively as a corporate lawyer and in the Justice Department previously as attorney general, deputy attorney general and head of the Office of Legal Counsel.

“He runs a very efficient and principled organization, and I fully expect people will respond very positively to that,” said George Terwilliger, a former deputy attorney general and close friend of Barr’s.

Joyce Vance, a former U.S. attorney in the Obama administration and a Trump critic, said Barr will be tested early on.

“Barr, if he wants to be the people’s lawyer and not the president’s lawyer, is going to have to walk the high ground, not just in his private dealings inside of the Justice Department but publicly,” Vance said. “He’s going to have to set a clear example that when it comes to individual criminal investigations he’s independent from the White House, and that’s not what this president wants from an attorney general.”

Complicating Barr’s position is the fact that his son-in-law, Tyler McGaughey, a Justice Department lawyer, recently began working in the White House Counsel’s Office. McGaughey, who had been prosecuting major crimes in the U.S. attorney’s office in Alexandria, was among several lawyers there who have been detailed to the White House. McGaughey sought the assignment before Barr’s nomination to be attorney general, according to people familiar with the situation.

Barr also took over as attorney general just as McCabe was on a media blitz to promote his new book, “The Threat: How the FBI Protects America in the Age of Terror and Trump.”

McCabe has been airing unflattering, behind-the-scenes details of his discussions with and about Trump. In recent interviews, he has described how he opened an investigation into Trump personally after the president fired James B. Comey as FBI director in May 2017 — and how officials contemplated even more dramatic steps. McCabe singled out in particular Rosenstein, the current No. 2 Justice Department official. McCabe says Rosenstein raised the question of which Cabinet member might support using the 25th Amendment to oust Trump, as well as the idea of wearing a wire into the White House to secretly record what the president was saying.

The allegations first emerged late last year and nearly cost Rosenstein his job at the time, and McCabe’s television tour this past week seemed to inflame those old wounds. On Twitter, Trump lashed out at both McCabe and Rosenstein. He quoted conservative commentator Dan Bongino saying Monday on “Fox & Friends,” “This was an illegal coup attempt on the President of the United States.” And he cited the current criminal investigation into McCabe over allegations that he lied to investigators exploring a media disclosure.

“Wow, so many lies by now disgraced acting FBI Director Andrew McCabe,” Trump tweeted. “He was fired for lying, and now his story gets even more deranged.”

While Trump’s comment about Rosenstein might be perceived as pressing Barr to remove him as deputy attorney general, that die already had been cast. Rosenstein has been saying for weeks that he planned to step down soon after Barr was confirmed, and Barr — as a condition of taking the job — insisted on selecting his own top deputy.

A Justice Department official said Monday that Rosenstein planned to step down in mid-March for reasons unconnected to McCabe’s allegations. The administration on Tuesday announced that Trump is nominating Jeffrey Rosen — the deputy secretary of transportation, who worked previously at Kirkland & Ellis, the firm where Barr also previously worked — to replace him.

Barr said in a statement that Rosen is a “distinguished lawyer who has served at the highest levels of government and the private sector,” and he thanked Rosenstein for serving the Justice Department “over many years with dedication and distinction.”

Trump’s recent comments foreshadow what is likely to be a tense reality for Barr: The president could attack him or the department he leads in ways that defy historical norms.

“The bed was on fire when he got into it, so to speak,” Blumenthal said.

When Sessions was the country’s top law enforcement official, Trump undermined and diminished him relentlessly — even declaring at one point that he had no attorney general. Trump was incensed by Sessions’s recusal from oversight of special counsel Robert S. Mueller III’s Russia investigation because of his conflict of interest as a top Trump campaign surrogate, a problem that Barr does not face.

Barr and the Justice Department have not responded to Trump’s recent tweets, and in some ways, their hands are tied. In addition to facing possible criminal exposure, McCabe has said he plans to sue the department over his termination, which he believes was retaliation for having opened an investigation into Trump. Barr’s commenting could affect both the criminal probe into McCabe and the litigation over his expected suit.

Some Justice Department officials were uneasy at the time about how quickly McCabe opened an investigation into Trump, people familiar with the matter have said. Senate Judiciary Committee Chairman Lindsey O. Graham (R-S.C.) vowed to investigate the matter, using subpoenas if necessary.

If there was impropriety — by Rosenstein, McCabe or anyone else — it would be up to Barr to determine whether they should face discipline or whether department policies need to change.

“Obviously, those are matters that raise really serious concerns and questions about what was going on inside the FBI at the time,” Terwilliger said.

President Trump’s then-nominee for attorney general William P. Barr on Jan. 15 said he would release the Russia report “consistent with” regulations. (JM Rieger/The Washington Post)

Rachel Weiner contributed to this report.