Pakistan's main spy agency says homegrown Islamist militants have overtaken the Indian army as the greatest threat to national security, a finding with potential ramifications for relations between the two rival South Asian nations and for the U.S.-led war in Afghanistan.

A recent internal assessment of security by the Inter-Services Intelligence, Pakistan's powerful military spy agency, determined that for the first time in 63 years it expects a majority of threats to come from Islamist militants, according to a senior ISI...