WASHINGTON — President Trump gave firm instructions in March to the White House’s top lawyer: stop the attorney general, Jeff Sessions, from recusing himself in the Justice Department’s investigation into whether Mr. Trump’s associates had helped a Russian campaign to disrupt the 2016 election.

Public pressure was building for Mr. Sessions, who had been a senior member of the Trump campaign, to step aside. But the White House counsel, Donald F. McGahn II, carried out the president’s orders and lobbied Mr. Sessions to remain in charge of the inquiry, according to two people with knowledge of the episode.

Mr. McGahn was unsuccessful, and the president erupted in anger in front of numerous White House officials, saying he needed his attorney general to protect him. Mr. Trump said he had expected his top law enforcement official to safeguard him the way he believed Robert F. Kennedy, as attorney general, had done for his brother John F. Kennedy and Eric H. Holder Jr. had for Barack Obama.

Mr. Trump then asked, “Where’s my Roy Cohn?” He was referring to his former personal lawyer and fixer, who had been Senator Joseph R. McCarthy’s top aide during the investigations into communist activity in the 1950s and died in 1986.