WASHINGTON — Quickly after he undercut President Trump’s baseless claims of widespread voter fraud in early December, Lawyer Basic William P. Barr’s time atop the Justice Division hurtled to its finish. The president and his allies attacked Mr. Barr in private and non-private, making clear that he ought to retract his evaluation or spend the final weeks of the administration belittled and probably fired in humiliating trend.

Mr. Barr set to work on a face-saving exit plan, in response to individuals conversant in his efforts. He and allies started back-channel communications with the White Home to gauge his possibilities at an amicable parting, and he spent a weekend writing a letter that might announce his departure whereas preserving his relationship with the president.

The trouble succeeded in allowing Mr. Barr to leave largely on his phrases. Mr. Trump heaped reward on Mr. Barr in asserting his exit, and the lawyer basic returned the favor, blurring the truth that he had been all however pushed out.

The orchestrated farewell was a mirrored image of how Mr. Barr navigated his tenure operating a Justice Division for a president who considered it as hostile towards him. Mr. Barr’s time was largely outlined by the notion that he set aside the department’s independence to advance the president’s political and private pursuits, mainly by undermining its personal investigation into Russia and the Trump marketing campaign and by wading into marketing campaign points, together with taking part in up fears of voter fraud.

However Mr. Barr additionally confirmed flashes of autonomy on the finish of his tenure. His reversal on voter fraud broke from the president. He mentioned he saw no need for a particular counsel to research President-elect Joseph R. Biden Jr.’s son Hunter as Mr. Trump clamored for one. And Mr. Barr even acknowledged that a few of his suspicions concerning the Obama administration’s examination of Russian election interference had been misguided.

Historians will debate whether or not Mr. Barr, 70, was making an attempt to protect his fame. Already a polarizing determine, he had confronted a brand new groundswell of criticism in latest weeks for relieving restrictions on election-related investigations as Mr. Trump ramped up his complaints about voting irregularities and for guaranteeing that the division’s examination of the Russia investigation continues into the Biden administration.

Mr. Barr’s allies say he merely adopted his instincts, honed by his maximalist view of government energy, and was untroubled by perceptions that he was serving Mr. Trump’s private agenda.

Both approach, an examination of Mr. Barr’s tenure, based mostly on interviews with allies, critics, present and former legislation enforcement officers and teachers, reveals that it doesn’t matter what Mr. Barr says or does, Mr. Trump will in the end outline his legacy as lawyer basic.

“Invoice Barr shall be inexorably tied to Donald Trump,” mentioned Nancy Baker, a political scientist who research attorneys basic and interviewed Mr. Barr for an oral historical past venture by the Miller Heart on the College of Virginia. Whereas administration critics credited Mr. Barr for refuting Mr. Trump’s false election assertions, in the end, she mentioned, “he’ll all the time be Trump’s man.”

Mr. Barr, who left the job final week, mentioned at his remaining information convention that he accepted the publish as a result of he felt he might assist the division throughout a fraught interval.

“I knew I used to be signing up for a troublesome task on this division. As I’ve mentioned, there have been tough occasions,” mentioned Mr. Barr, who declined to reply questions for this text. “I don’t remorse coming in as a result of I feel it’s all the time an honor to serve the nation.”

When Mr. Barr, who had been lawyer basic through the first Bush administration, returned to the workplace early final yr, some Trump critics considered his expertise as a possible examine on the president. However his personal report confirmed that Mr. Barr regarded presidential power as broad, and Mr. Trump supplied an opportunity to revive what Mr. Barr noticed as government authority misplaced within the post-Watergate period.

“As a cupboard member, the lawyer basic was supportive of the administration and lots of of its priorities. He was unfairly criticized for that,” mentioned Brian Rabbitt, his former chief of employees and the outgoing head of the Justice Division’s prison division. “However you don’t take a job like his to withstand. You’re taking the job to assist the administration do its greatest for the nation.”

Mr. Barr was obsessed with points together with increasing non secular freedoms and supporting Native American reservations and tribal legislation enforcement places of work, former colleagues mentioned, and he largely continued his Bush-era struggle towards medicine, violent crime and what he deemed to be politically motivated prosecutions.

That work was eclipsed by the Russia investigation, which each he and Mr. Trump believed represented an abuse of energy by the F.B.I.

“He had a vigilante angle towards the Russia investigation — ‘I alone will repair this,’” mentioned Rebecca Roiphe, a professor at New York Legislation College who research the historical past and ethics of the authorized occupation.

After his February 2019 affirmation, Mr. Barr launched into what division officers mentioned was a single-minded mission to show any wrongdoing by investigators.

Mr. Barr started by reshaping the public’s perception of essentially the most politically charged investigation in a technology in the absolute best gentle for Mr. Trump. He went on to border it as a political cudgel used to “sabotage” Mr. Trump’s presidency, even after the Justice Division’s inspector basic concluded in any other case. “Prosecutors can typically turn into headhunters, consumed with taking down their goal,” Mr. Barr said this fall. He said in his remaining days in workplace that the investigators for the particular counsel, Robert S. Mueller III, had been too biased to show F.B.I. wrongdoing.

Mr. Barr went past discuss, tapping John H. Durham, the U.S. lawyer in Connecticut, to open a prison investigation into the origins of the Russia inquiry. Mr. Barr talked up Mr. Durham’s work within the months earlier than the election, flouting Justice Division norms to keep away from publicly discussing ongoing prison investigations as Mr. Trump promoted the inquiry as sure to show a “deep state” plot towards him.

“He had a blind spot on Russia,” Ms. Baker mentioned of Mr. Barr. “Blind to the truth that he acted politically in his remedy of the Russia investigation, even when in his thoughts he acted out of his perception that his actions had been per the rule of legislation.”

After the election, amid a storm of complaints from Mr. Trump’s allies that Mr. Durham had not revealed info that would have helped the president, Mr. Barr downplayed expectations that he would expose prison acts. He told a Wall Street Journal opinion columnist that by focusing solely on indictments, the political class excuses different contemptible habits.

And although in the identical interview he backed off his suspicions of the C.I.A.’s examination of Russian election interference in 2016, he additionally confirmed Mr. Durham was nonetheless reviewing the 2017 intelligence neighborhood evaluation about Russian election interference.

Contained in the Justice Division, the turning level got here with Mr. Barr’s interventions in two high-profile circumstances stemming from the Russia inquiry, these of Mr. Trump’s longtime buddy Roger J. Stone Jr. and his former nationwide safety adviser Michael T. Flynn. Some prosecutors withdrew from the circumstances. Just a few left the division completely. A sometimes discreet work drive started to call for Mr. Barr’s resignation and accuse him of turning the division “right into a shield to protect the president” and a instrument for Mr. Trump to settle political scores.

Mr. Barr rebuffed these allegations, publicly rebuking Mr. Trump for opining on the Stone case. Former aides mentioned Mr. Barr was conveying the message to each Mr. Trump and federal prosecutors that he acts based mostly on his convictions, not politics.

However Mr. Barr’s interventions in ways in which benefited Mr. Trump prolonged past the particular counsel investigation. Analyzing Mr. Trump’s dealings with Ukraine that prompted impeachment, the Justice Division shortly decided he had not dedicated a marketing campaign finance crime, nicely earlier than the president’s broad efforts to stress Kyiv got here into focus.

The division additionally took on lawsuits over books written by Trump adversaries. Within the case of the previous nationwide safety adviser John R. Bolton, who had fallen out of Mr. Trump’s favor, it opened a criminal inquiry into whether or not he illegally disclosed categorised info.

Being a profitable lawyer basic “isn’t just about doing the correct factor, it’s about preserving the legitimacy of the establishment,” Ms. Roiphe mentioned. “Even when he actually held these beliefs, he addressed them in ways in which had been solely revered by his personal political followers.”

Some Justice Division officers believed that Mr. Barr privately honed the president’s perception that his lawyer basic was his political fixer and used that capital with Mr. Trump to guard the division, shielding it from blowback when it prosecuted circumstances that interfered in commerce negotiations with China and to guard the F.B.I. director, Christopher A. Wray, from being fired over the president’s animosity towards the bureau.

Buffeted by assault, Mr. Barr saved an unusually small interior circle of aides and relied on them, quite than the heads of the division’s divisions, for recommendation, in response to former officers.

Mr. Barr appeared to scorn enter from elsewhere within the division, significantly from the profession employees, as pointless noise that slowed down his quick deliberative course of, former officers mentioned.

Mr. Barr made his low opinion clear in a speech this yr, saying that no profitable organizations deemed choices by low-level staff “sacrosanct” or deferred to “no matter these subordinates need to do.”

However he appeared blindsided by a string of miscues earlier this yr, mainly his management of the federal response to this yr’s nationwide protests over racial injustice. Mr. Barr got here beneath fireplace for ordering federal officers to clear a park close to the White Home in June simply earlier than Mr. Trump’s widely criticized photo op outdoors a church. Irritating some within the White Home, he additionally contradicted Mr. Trump’s clarification for sheltering in a bunker throughout protests.

And later that month, Mr. Trump distanced himself virtually instantly from Mr. Barr’s dismissal of the highest federal prosecutor in Manhattan.

In his remaining weeks, Mr. Barr started to see Mr. Trump’s agenda, which he supported, as separate from the president himself and his private shortcomings, like his refusal to just accept the outcomes of the election, associates mentioned.

Mr. Barr accepted Mr. Biden’s win and mentioned no quantity of fraud he had seen would overturn it. He had already resisted Mr. Trump’s stress late within the marketing campaign to prosecute Democrats.

He additionally saved quiet the doubtless explosive information that Hunter Biden was under criminal investigation. Disclosing that, associates mentioned, might have undermined a future Biden presidency, an act Mr. Barr noticed as a possible echo of the investigation opened 4 years earlier into Mr. Trump.