WASHINGTON — President Trump ordered the firing last June of Robert S. Mueller III, the special counsel overseeing the Russia investigation, according to four people told of the matter, but ultimately backed down after the White House counsel threatened to resign rather than carry out the directive.

The West Wing confrontation marks the first time Mr. Trump is known to have tried to fire the special counsel. Mr. Mueller learned about the episode in recent months as his investigators interviewed current and former senior White House officials in his inquiry into whether the president obstructed justice.

Amid the first wave of news media reports that Mr. Mueller was examining a possible obstruction case, the president began to argue that Mr. Mueller had three conflicts of interest that disqualified him from overseeing the investigation, two of the people said.