Attorney General William P. Barr has told people close to President Trump — both inside and outside the White House — that he is considering quitting over Trump’s tweets about Justice Department investigations, three administration officials said, foreshadowing a possible confrontation between the president and his attorney general over the independence of the Justice Department.

So far, Trump has defied Barr’s requests, both public and private, to keep quiet on matters of federal law enforcement. It was not immediately clear Tuesday whether Barr had made his posture known directly to Trump. The administration officials said Barr seemed to be sharing his position with advisers in hopes the president would get the message that he should stop weighing in publicly on the Justice Department’s ongoing criminal investigations.

“He has his limits,” said one person familiar with Barr’s thinking, speaking on the condition of anonymity, like others, to discuss internal deliberations.

Late last week, Barr publicly warned the president in a remarkable interview with ABC News that his tweets about Justice Department cases “make it impossible for me to do my job.” Trump, White House officials said, is not entirely receptive to calls to change his behavior, and he has told those around him he is not going to stop tweeting about the Justice Department. They said Trump considers highlighting what he sees as misconduct at the FBI and Justice Department as a good political message.

The standoff between Trump and Barr intensified Tuesday when Trump declared in a string of early morning tweets that he might sue those involved in the special counsel investigation into his 2016 campaign and suggested that Roger Stone, his friend convicted of lying to Congress in that probe, deserved a new trial.

Hours later, a Justice Department official said prosecutors had filed a sealed motion in court arguing the opposite and that they had Barr’s personal approval to do so.

Barr had a previously scheduled lunch with the White House counsel Tuesday and was still the attorney general by day’s end — indicating that the president’s moves that day were not enough to push him to resign. But he and his Justice Department seemed to remain mired in a political crisis, with an uncertain future.

A Justice Department spokeswoman initially declined to comment. After this article appeared online, Kerri Kupec, a spokeswoman for Barr, said on Twitter, “Addressing Beltway rumors: The Attorney General has no plans to resign.” She did not address what Barr had told others.

White House spokespeople did not respond to questions for this report. Some people familiar with Barr’s thinking cautioned that he would not make a hasty decision to leave, and it is unclear what precisely would trigger him to take such a dramatic step.

It was only a week ago that Trump’s tweet about federal prosecutors’ recommendation that Stone should be sentenced to seven to nine years in prison created a crisis at the Justice Department.

After that tweet, Barr moved to intervene and reduce the recommendation. The four career prosecutors assigned to the matter quit the case, with one leaving the government entirely. Barr has insisted that he made up his mind to get involved before Trump weighed in, but he faced significant skepticism inside and outside the Justice Department.

Over the weekend, more than 2,000 former department employees signed a public letter urging Barr to resign over his handling of the Stone case and exhorted current department employees to report any unethical conduct to the inspector general. Jan Miller, who was the U.S. attorney for central Illinois from 2002 until 2005 under President George W. Bush, said he signed in part to remind rank-and-file Justice Department employees that “they’re not alone.”

“I’m sure it’s a very difficult time to be a line prosecutor in the department right now,” Miller said.

White House press secretary Stephanie Grisham played down the letter’s significance, saying there were “obstructionists all across this government who are working against the president.” Senate Majority Leader Mitch McConnell (R-Ky.) and Senate Judiciary Committee Chairman Lindsey O. Graham (R-S.C.) also came to Barr’s defense in a joint statement.

“The nation is fortunate that President Trump chose such a strong and selfless public servant to lead the Department of Justice,” they wrote. “We expect that, as always, efforts to intimidate the Attorney General will fall woefully short.”

People close to Barr say he is unlikely to be moved by the letter from the former Justice Department employees, which bears the signatures of many who have long been vocal opponents of his. But Barr, the people said, is deeply concerned about morale inside the department, and that is in part why he chastised the president publicly to ABC News.

In the weeks before the interview, Barr had also privately asked the president to stop speaking publicly on Justice Department matters, a person familiar with their discussions said. But his comments have apparently fallen on deaf ears. The day after Barr’s ABC interview, Trump tweeted that he had the “legal right” to ask Barr to intervene in a criminal case.

Trump said Tuesday that he has “total confidence” in Barr and conceded, “I do make his job harder.” He also asserted, though, that he, rather than his attorney general, is “the chief law enforcement officer of the country.”

“The attorney general is a man with great integrity,” Trump said. “I chose not to be involved. I’m allowed to be involved. I could be involved if I want to be.”

Trump has raged privately for months about the Justice Department’s not charging those he considers political foes, and people familiar with the matter say he is particularly upset by the decision revealed last week not to charge former acting FBI director Andrew McCabe with lying to investigators exploring a media disclosure.

McCabe authorized the FBI to begin investigating Trump personally in 2017 for possible obstruction of justice in connection with the probe into whether his campaign coordinated with Russia, and Trump has suggested he might sue those involved. That case was ultimately taken over by special counsel Robert S. Mueller III.

Trump also has complained to associates that he has not been able to view the findings of U.S. Attorney John Durham, whom Barr tasked with examining the Russia probe’s origins. Durham’s probe is ongoing, and he has not yet prepared any report detailing his conclusions, a person familiar with the matter said.

People familiar with the matter said Trump has no plans to remove Barr as attorney general, despite his frustrations. Apart from his ABC News interview, Barr has been a particularly loyal and effective Cabinet secretary for Trump, willing to take political heat for the commander in chief.

Barr absorbed significant criticism for casting the findings of Mueller’s investigation in a way that some saw as overly favorable to Trump, and for commissioning internal Justice Department reviews of politically sensitive matters, including the Russia probe.

But Barr has been persistently vexed by Trump’s tweets, and he saw the president’s commentary on Stone last week as something of a last straw.

Trump had largely refrained from law enforcement commentary over the holiday weekend before erupting once more on Tuesday morning. The president quoted at length Andrew Napolitano, a former New Jersey Superior Court judge and Fox News commentator who, by Trump’s telling, argued that Stone should receive a new trial because of “the unambiguous & self outed bias of the foreperson of the jury.”

“Pretty obvious he should (get a new trial),” Trump quoted Napolitano as saying.

Trump also reprised old attacks on the Mueller investigation.

“The whole deal was a total SCAM. If I wasn’t President, I’d be suing everyone all over the place,” Trump wrote. “BUT MAYBE I STILL WILL. WITCH HUNT!”

Grisham, the press secretary, said Tuesday that “the president’s obviously frustrated.”

“For three years, he has been under attack in one way or the other, and the Mueller report is another example of that,” Grisham said during an appearance on “Fox & Friends,” during which she also alluded to the Stone case. “I mean the foreperson of a jury was somebody who was very vocal about not liking President Trump or his supporters. . . . That’s scary stuff.”

The tweets came just before prosecutors and defense attorneys convened for a hearing in the Stone case to determine whether Stone’s request for a new trial needed to be resolved before his sentencing, scheduled for Thursday. Stone’s team had demanded the new trial Friday, one day after Trump suggested that the forewoman in the federal case had “significant bias.”

Trump was referring to Tomeka Hart, a former president of the Memphis City Schools Board of Commissioners and an unsuccessful Democratic candidate for Congress. Hart has identified herself as the forewoman of the jury in a Facebook post, saying she “can’t keep quiet any longer” in the wake of a Justice Department move to reduce prosecutors’ sentencing recommendation for Stone.

U.S. District Judge Amy Berman Jackson, who is presiding over Stone’s case, decided that Stone will be sentenced Thursday, though the “execution of the sentence will be deferred” while she decides whether Stone deserves a new trial. The Justice Department is notably opposing Stone in that matter — with Barr’s approval — and a Justice Department official said that decision “was made independent of the White House.”

Trump told reporters Tuesday that he thought Stone had been “treated unfairly” but that he had not given any thought to pardoning him. Trump did grant clemency to others Tuesday, including a commutation for Rod Blagojevich, a former Illinois governor who was convicted on corruption charges in 2011 related to trying to sell President-elect Barack Obama’s vacated Senate seat, and a pardon for Bernard Kerik, a former New York police commissioner jailed on eight felony charges, including tax fraud.

Asked whether Stone deserves any prison time, Trump demurred, saying, “You’re going to see what happens.”

Stone has been a friend and adviser to Trump since the 1980s and was a key figure in his 2016 campaign, working to discover damaging information on Democratic opponent Hillary Clinton.

A jury convicted Stone in November on charges of witness tampering and lying to Congress about his efforts to gather damaging information about Clinton. Stone’s were the last charges arising from Mueller’s investigation into Russian interference in the 2016 election.

Stone’s defense has asked for a sentence of probation, citing his age, 67, and lack of criminal history.

Mark Berman, Spencer S. Hsu and Devlin Barrett contributed to this report.