The surprising information about the Islamic State leader Abu Bakr al-Baghdadi’s general location — in a village deep inside a part of northwestern Syria controlled by rival Qaeda groups — came following the arrest and interrogation of one of Mr. al-Baghdadi’s wives and a courier this past summer, two American officials said.

Armed with that initial tip, the C.I.A. worked closely with Iraqi and Kurdish intelligence officials in Iraq and Syria to identify Mr. al-Baghdadi’s more precise whereabouts and to put spies in place to monitor his periodic movements, allowing American commandos to stage an assault Saturday in which President Trump said Mr. al-Baghdadi died.

But Mr. Trump’s abrupt decision to withdraw American forces from northern Syria disrupted the meticulous planning and forced Pentagon officials to press ahead with a risky, night raid before their ability to control troops and spies and reconnaissance aircraft disappeared, according to military, intelligence and counterterroism officials. Mr. al-Baghdadi’s death, they said, occurred largely in spite of Mr. Trump’s actions.