But the Pakistanis offered a more nuanced portrait. They said the contacts were less threatening than the American officials depicted and were part of a strategy to maintain influence in Afghanistan for the day when American forces would withdraw and leave what they fear could be a power vacuum to be filled by India, Pakistan’s archenemy. A senior Pakistani military officer said, “In intelligence, you have to be in contact with your enemy or you are running blind.”

The ISI helped create and nurture the Taliban movement in the 1990s to bring stability to a nation that had been devastated by years of civil war between rival warlords, and one Pakistani official explained that Islamabad needed to use groups like the Taliban as “proxy forces to preserve our interests.”

A spokesman at the Pakistani Embassy in Washington declined to comment for this article.

Over the past year, a parade of senior American diplomats, military officers and intelligence officials has flown to Islamabad to urge Pakistan’s civilian and military leaders to cut off support for militant groups, and Washington has threatened to put conditions on more than $1 billion in annual military aid to Pakistan. On Saturday, the director of the C.I.A., Leon E. Panetta, met with top Pakistani officials in Islamabad.

Little is publicly known about the ISI’s S Wing, which officials say directs intelligence operations outside of Pakistan. American officials said that the S Wing provided direct support to three major groups carrying out attacks in Afghanistan: the Taliban based in Quetta, Pakistan, commanded by Mullah Muhammad Omar; the militant network run by Gulbuddin Hekmatyar; and a different group run by the guerrilla leader Jalaluddin Haqqani.

Dennis C. Blair, the director of national intelligence, recently told senators that the Pakistanis “draw distinctions” among different militant groups.

“There are some they believe have to be hit and that we should cooperate on hitting, and there are others they think don’t constitute as much of a threat to them and that they think are best left alone,” Mr. Blair said.

The Haqqani network, which focuses its attacks on Afghanistan, is considered a strategic asset to Pakistan, according to American and Pakistani officials, in contrast to the militant network run by Baitullah Mehsud, which has the goal of overthrowing Pakistan’s government.