If we leave Afghanistan, there is a risk that al Queda will return and plan a new attack. The obvious solution is to cut a deal with India whereby she will guarantee no al Queda in exchange for our support in struggle with Pakistan.
Indeed an obvious solution, but a dangerous one. Pakistan could retaliate by invading India.
In the end, India will dominate Pakistan anyway, so we might as well bless Indian South Asian dominance right now. In the long run, India is the regional power (not Iran) and a bulwark against Chinese influence.
That is one of the reasons why we are anxious not to upset India. But India is not that stable. It has a major insurgency in its eastern states, has border disputes with China and a continuing "cold war" with Pakistan. Leaving India to rule the roost could end up with a major regional conflict. Might do anyway, if we get global cooling and food shortages.