WASHINGTON — President Trump knew the Central Intelligence Agency and Special Operations commandos were zeroing in on the location for Abu Bakr al-Baghdadi, the Islamic State leader, when he ordered American troops to withdraw from northern Syria earlier this month, intelligence, military and counterterrorism officials said on Sunday.

For months, intelligence officials had kept Mr. Trump apprised of what he had set as a top priority, the hunt for Mr. al-Baghdadi, the world’s most wanted terrorist.

But Mr. Trump’s abrupt withdrawal order three weeks ago disrupted the meticulous planning underway and forced Pentagon officials to speed up the plan for the risky night raid before their ability to control troops, spies and reconnaissance aircraft disappeared with the pullout, the officials said.

Mr. al-Baghdadi’s death in the raid on Saturday, they said, occurred largely in spite of, and not because of, Mr. Trump’s actions.