But Mr. Trump’s advisers saw him as the perfect replacement for Attorney General Jeff Sessions when the president forced him out in November: someone with Republican establishment gravitas and distinguished legal pedigree who seemed to share at least some of the president’s views.

Mr. Barr had publicly called Mr. Mueller’s investigation of obstruction of justice accusations against the president “asinine” and, in a memo he gave to Justice Department officials, “grossly irresponsible.” He had said he saw far less reason to scrutinize the Trump campaign’s ties to Russia than to investigate whether donations to Hillary Clinton’s family foundation had influenced her actions as secretary of state.

Among those who recommended him was Abbe D. Lowell, the criminal defense lawyer representing Mr. Trump’s son-in-law, Jared Kushner, and daughter Ivanka. Finally, Mr. Barr’s expansive view of executive powers suggested he would strongly defend Mr. Trump from House Democrats determined to uncover his hidden tax records and more.

Ms. McGaughey said her father “really struggled deciding whether or not to do this.” J. Michael Luttig, a former appeals court judge and longtime friend, said he ultimately decided he was unwilling to sit on the sidelines “at a moment when the country is wrapped around the axle to the point of constitutional and political paralysis.”

He had two goals, which he is now executing, friends said: to serve as a firewall between the White House and the Justice Department, which he reveres, and to keep the crisis unleashed by the investigation of Mr. Trump from weakening the presidency. Critics like Paul Rosenzweig, a former prosecutor, said that what he is actually doing is “putting his thumb on the scale” for Mr. Trump.

Mr. Rosenzweig served on the independent counsel team that investigated President Clinton and as a homeland security official under President George W. Bush. A critic of Mr. Trump, he called Mr. Barr “a situational ethicist who sees legal issues through the prism of what benefits him and his party.”

Mr. Barr’s decisions after he received the evidence from Mr. Mueller’s two-year investigation are likely to long be debated. Both men were on unplowed ground, without obvious historical precedent or definitive Justice Department guidelines. They disagreed on legal issues, what to tell the public and when, and it appears, the gravity of the accusations against Mr. Trump.