Across Afghanistan, behind the obvious battles fought for this country's soul, a shadow war is being quietly waged. It's being fought with spies and proxies, with hundreds of millions of dollars in aid money and ominous diplomatic threats. The fight pits nuclear-armed rivals India and Pakistan against one another in a battle for influence that will almost certainly gain traction as the clock ticks down toward America's military withdrawal, which President Barack Obama has announced will begin next year. The clash has already sparked bloody militant attacks, and American officials fear the region could become further destabilized. With Pakistani intelligence maintaining ties to Afghanistan's Taliban militants, India has threatened to draw Iran, Russia and other nations into the competition if an anti-Indian government comes to power in Kabul. “This is a delicate game going on here,” said Daoud Muradian, a senior adviser to the Afghan Foreign Ministry. He spoke wearily about how Afghanistan, a mountainous crossroads linking South Asia, the Middle East and Central Asia, has for centuries often been little more than a stage for other countries' power struggles. “We don't want to be forced to choose between India and Pakistan.” For both India and Pakistan, Afghanistan is an exceedingly valuable prize. To India, ties with Kabul mean new trade routes, access to Central Asia's vast energy reserves and a way to stave off the rise of militancy. It means the chance for New Delhi to undermine Islamabad as it nurtures its superpower aspirations by expanding its regional influence. While Pakistan is also desperate for new energy supplies, its Afghan policy has been largely shaped by the view that Afghanistan is its natural ally. The two countries share a long border, overwhelmingly Muslim populations and deep ethnic links. Then there is fear. Pakistan and India have already fought three wars over the past seven decades, and Pakistani military leaders are terrified of someday being trapped militarily between India on one border and a pro-IndiaAfghanistan on the other. “We can't afford an unfriendly government in Afghanistan,” said Mohammad Sadiq, Pakistan's ambassador to Afghanistan. The shadow war began in earnest in the wake of the 2001 US invasion, when the Taliban government was forced from power and New Delhi began courting Afghanistan's new leaders. It was a move into a country that Islamabad, a fierce supporter of the Taliban government, had seen as its diplomatic territory for two decades. But New Delhi quickly became a close ally of President Hamid Karzai, who traveled to India recently for talks aimed at strengthening ties between the two countries. On the surface, both India and Pakistan are bringing help to a country that desperately needs it. New Delhi has built highways in the western deserts and brought electricity to Kabul. It is constructing a new Parliament building and offers free medical care in clinics across Afghanistan. Despite its immense spending needs- India has widespread poverty and staggering infrastructure problems despite its rapidly growing economy -it has given more than $1.3 billion in development aid. That, in turn, has sparked Pakistani efforts, with Islamabad spending about $350 million on everything from school textbooks to buses. But this is far from pure humanitarianism. Gen. Stanley McChrystal, the top US and NATO commander in Afghanistan, laid out the situation bluntly: “While Indian activities largely benefit the Afghan people, increasing Indian influence in Afghanistan is likely to exacerbate regional tensions and encourage Pakistani countermeasures,” he warned in a report late last year. Heightened tensions are the last thing the US wants. The Afghan war has killed more than 1,800 coalition soldiers – more than 1,100 of them Americans. More than 2,400 Afghan civilians were killed just last year. If the competition over Afghanistan is rooted in a cocktail of issues, much of it revolves around the Taliban. New Delhi's perceptions of modern Afghanistan have been molded by its memories of the 1996-2001 Taliban government, the fundamentalist Muslim regime which rose to power with Pakistan's help. It was a time when New Delhi was openly despised in Kabul, when anti-India insurgents trained in Afghan camps and the hijackers of an Indian airliner were welcomed here as heroes. Even after the Taliban government fell, Pakistan's powerful spy agency, Inter-Services Intelligence, or ISI, retained links to the Taliban insurgency now battling the American-led forces and the Karzai government, in case the Taliban ever return to power. But if there's one thing New Delhi does not want, it's another militant Islamic government in Kabul. “We want the stabilization of Afghanistan because it is directly related to our security. Plain and simple,” said Jayant Prasad, the Indian ambassador to Afghanistan, speaking inside his heavily guarded Kabul residence. India has paid heavily for its Afghan involvement. The Indian Embassy was bombed in 2008 and again last year, leaving 75 people dead. Six Indians were killed by militants during the construction of an India-funded highway. Two Kabul guest houses popular among Indians have been attacked. The last attack, in February, left at least six Indians dead and forced New Delhi to temporarily close its medical and teaching missions in Kabul. India blamed that attack on the Pakistan-based militant group Lashkar-e-Taiba, the same group believed to be behind the 2008 Mumbai terrorist attacks. India and the United States have both said the embassy attacks were carried out by militants allied to Pakistan's ISI. The Pakistanis “are bringing the proxy war to Afghanistan and we are the targets,” said Prasad. It's an accusation that Pakistan angrily denies. “India has always used Afghanistan against us,” said Sadiq, the Pakistani ambassador.Karzai has made little secret of his preference for India. The president, who was educated in India, has loudly welcomed New Delhi's assistance while rarely mentioning Pakistan's aid. Other Afghan officials barely disguise their distrust of Pakistan. Pakistan wants “a puppet state in Kabul, a subservient state,” said Muradian, the foreign ministry adviser. “India wants a stable, pluralistic Afghanistan.” Certainly, India has shown it is willing to play diplomatic hardball. Even India's allies say New Delhi has a large presence in Afghanistan from its foreign intelligence agency, the Research and Analysis Wing, or RAW. At least one victim of the February guest house attack was an undercover RAW agent, a senior Afghan official said on condition of anonymity because of the sensitivity of the issue. According to Islamabad, many of those agents are providing support to separatist militants in Pakistan's Baluchistan province -an accusation New Delhi denies. The reality remains murky. Pakistan keeps Baluchistan largely sealed off to outsiders. Western diplomats, speaking on condition of anonymity, say Indian intelligence is believed to be in contact with the Baluchi separatists, though it's unclear if they provide any support. India also is keeping in reserve its longtime links to Afghan warlords, in case Afghanistan is again divided by violence. For years, New Delhi supplied the leaders of the Northern Alliance, the collection of ethnic militias that battled the Taliban (and often one another), with food, intelligence and medical care. Later, after the Alliance helped the US oust the Taliban in 2001, the warlords scattered into government and business and sometimes into crime or exile. But India remains in close contact with a range of the former militia leaders, according to people with close ties to New Delhi's foreign policy elite, speaking on condition of anonymity because they were not authorized to speak to the press. New Delhi's biggest worry is that US forces will withdraw from Afghanistan before Karzai's government is in full control of the country. An early withdrawal, India fears, could allow Islamabad and the Taliban militants to gain more power in Afghanistan and potentially even usher in another government hostile to New Delhi. While a full American pullout appears unlikely anytime soon, US military officials have angered New Delhi by talking about the possibility of allowing some Taliban to join the Afghan government. India warns it could form a coalition with Iran-an alliance that would infuriate Washington- if the Taliban appear poised to return to power. The “self-interested coalition” could include Russia and several Central Asian states that would also fear a Taliban return, according to an Indian with knowledge of the diplomatic maneuvering. For now, though, India's program to win Afghan hearts and minds is clearly working.