Some aides urged the president to increase the modest number of military advisers in Libya — roughly two dozen Special Operations soldiers at any given time. But the effort was stymied by Stephen K. Bannon, then Mr. Trump’s chief strategist.

Mr. Bannon clashed frequently with Mr. Trump’s national security adviser, Lt. Gen. H. R. McMaster, who, Mr. Bannon said, kept pushing for more American involvement in a variety of places, including Afghanistan, Syria and Yemen. “Every day there was a new ask with no overarching strategy,” Mr. Bannon recalled in an interview after leaving the White House but before his recent public break with Mr. Trump over his comments in a book about the administration’s first year. “Libya was what pushed me over the edge.”

Mr. Bannon was more open to an idea pitched by Erik D. Prince, a founder of the private security firm Blackwater Worldwide whom he had gotten to know when he oversaw the conservative website Breitbart News. Mr. Prince had proposed relying on contractors to tackle Libya’s security problems. It seemed, at least to Libyan officials, that the idea was gaining steam: One said Mr. Prince had approached them about it at a conference in London where he was seen with Sebastian Gorka, a Bannon ally and White House adviser at the time.

How was sending American troops to Libya in America’s interest? Mr. Bannon wanted to know.

At a wide-ranging Saturday morning meeting on July 8, Mr. Bannon took his complaints to Mr. Mattis, a retired Marine general. The country was a mess, Mr. Bannon said he told the secretary, and greater American involvement could only backfire.

Mr. Mattis listened politely, Mr. Bannon said, but pointed out that Libya, along with parts of Syria and the Philippines, was a critical battlefield in the global fight against the Islamic State. Mr. Bannon responded that if the president was going to be asked to get more deeply involved in Libya, he at least wanted Mr. Trump to have a “strategic overview of U.S. commitments around the globe, everything from military to trade agreements, so that all these requests could be put in a larger context.”

A three-hour follow-up meeting with the president took place on July 20 at the Pentagon. As Mr. Bannon had hoped, once the National Security Council convened to discuss hot spots around the world where the Pentagon might need to bolster its presence, Libya fell farther down the priority list.

At least for the moment, Mr. Bannon had won the day.

But if Mr. Trump’s Libya policy seemed unintelligible to some, the president of another world power had a far clearer vision.