Yet there were clear red lines that the ISI refused to cross, like carrying out operations in the tribal areas on the Afghan border where many Qaeda members hid, or arresting Afghan Taliban fighters, who were viewed as friendly proxies.

The two agencies were never fully comfortable with each other, according to a former senior C.I.A. official who spoke on condition of anonymity. “We never did the full monty with them,” said the former official. “There is always this little dance with them. We don’t trust them fully.”

Two former C.I.A. officials said they doubted the ISI as a whole sheltered Bin Laden, but it was possible current or former members may have helped him. Members of the ISI’s shadowy S wing — which directs operations outside of Pakistan and helped create the Taliban — were seen as particularly close to militants.

“There are rogue elements,” said the former senior official. “There was no shortage of people in the ISI who didn’t like us and would support the Islamic extremists.”

The distrust between the C.I.A. and ISI became so deep in the last several years that the C.I.A. created its own network of human intelligence that ran parallel and separate to the ISI, according to the former C.I.A. official. Pakistanis in the C.I.A.’s network were instrumental in tracking down the courier to Bin Laden, who was followed by the agents to the compound where the Qaeda leader was living, they said.

The ability to keep that network and develop it even further as a tool in fighting terrorism was one of many reasons the United States could not afford to abandon Pakistan by drastically cutting assistance, as was done in the 1990s, administration officials said.