Image caption Both Russia and China are seeking to exploit Afghanistan's largely untapped mineral reserves

With the United States and Nato set to leave Afghanistan over the next two years, power is the region is shifting. Writer Ahmed Rashid reports on Russia and China's attempts to capitalise on the decline of American influence in Pakistan and Afghanistan.

As United States troops prepare to leave Afghanistan in 2014, a major regional shift is underway.

With the prospect of a decline in US influence in the region in sight, Russia and China are reaching out to Pakistan and Afghanistan in a bid to improve economic ties and to secure their southern borders against the spread of Islamic fundamentalism.

The presidents of Afghanistan and Pakistan, Hamid Karzai and Asif Ali Zardari, are in Beijing this week for the summit meeting of the Shanghai Cooperation Organization (SCO), which is led by China and Russia.

With the US set to leave Afghanistan and bad relations between Islamabad and Washington DC continuing to fester, the SCO has taken on a new lease of life.

Economic help

China and Afghanistan will sign a strategic agreement at the SCO, elevating their relationship as China shops for raw material and oil exploration contracts in mineral-rich Afghanistan. China has already secured some oil and copper mining concessions.

Until now, China has carried out few development projects in Afghanistan and is unlikely to help fund the country's army and police, as the US would like.

But all that could change once the Americans leave. Xu Feihong, China's ambassador to Kabul says that ''China is the most reliable friend of Afghanistan".

Likewise Russia, both through the SCO and bilaterally, is willing to offer major help to Afghanistan such as improving the Salang Tunnel highway, the critical link road between Kabul and the north which the Soviets built in the 1970s.

After years of poor relations, Russia has also taken a major initiative with Pakistan.

Moscow sent its special representative and long-time regional expert Zamir Kabulov to Islamabad to suss out what the Pakistanis want and offer economic help, such as refurbishing Pakistan's one and only steel mill, built with Russian help in the 1970s.

Mixed messages

China is already Pakistan's closest and most reliable ally.

In early June, Chinese Foreign Minister Yang Jiechi visited Islamabad and pledged to stand by Pakistan in its tensions with the Americans.

He pleased the government by echoing Pakistan's refrain that the world should recognize Pakistan's ''huge sacrifices'' in the war on terror and help safeguard its sovereignty, rather than question Pakistan's intentions as the US has done recently.

If Pakistan can take steps against home grown extremism it will do much to convince Russia and China that it deserves help to move out of the American orbit.

Moreover, China is hoping to exploit Afghanistan's mineral resources once the war is over and knows that Pakistan could play a crucial role. It could well hire Pakistani companies as junior partners in its mineral explorations.

Until now, Mr Zardari has been looking to China to help bail him out of Pakistan's severe economic mess but China never gives cash, loans, budgetary support, development funds or humanitarian funds to other countries like Western governments do.

Instead, it carries out major projects that help the recipient but provide strategic spin offs for China too.

Despite his words of support, officials say Mr Yang also warned Pakistan's leaders not to break with the US and to avoid taking hardline positions regarding the US and Nato in Afghanistan.

For the past seven months, Pakistan has refused to reopen the main route for Nato supplies that runs from Karachi to the Afghan border. Talks with the US on the issue have so far failed.

Fearing fundamentalists

Both China and Russia will be happy to see US troops leave Afghanistan, but they are equally worried about the Taliban and other extremist groups penetrating Xinjiang province in southern China and the Central Asian republics, whose national security is very much in the hands of Russia.

China is deeply concerned by the long-running crisis in Pakistan, fearing that it may lead to a strengthening of Islamic fundamentalism.

Beijing is worried that any threat to Pakistan from internal insurgency or secessionist movements would only bolster its regional rival India.

So, for the first time ever China has held high-level discussions with US officials that have focused on the crisis in Pakistan and how both countries could nudge Pakistani leaders to do the right thing.

Image caption Afghan President Hamid Karzai (L) and Pakistani President Asif Ali Zardari are being courted by Russia and China

The US is also asking the Chinese help persuade the Pakistani military to be more helpful in Afghanistan and end the sanctuaries the Taliban enjoy.

Both the Chinese and Russians are worried about the threat posed by the Taliban and al-Qaeda themselves.

In an unprecedented move, over the past six months Chinese officials issued three strong statements rebuking Pakistan for not reining in Uighur extremists who are training with Pakistani extremist groups and fighting with the Taliban in Afghanistan.

Uighurs are Chinese Muslims from Xinjiang province and some are involved in an independence struggle against China.

'Tectonic shift'

Pakistan's military rushed to try and detain the Uighur militants. According to diplomats at the United Nations, China has been quietly telling the Pakistan military that it must end havens for all militant groups on its soil - a message that has been publicly taken up by Nato.

Russia also makes no bones about the fact that it sees Pakistan as harbouring Central Asian militant groups such as the Islamic Movement for Uzbekistan and Islamic Jihad.

These groups - which have been based in Pakistan's tribal areas - are now trying to enter Tajikistan and Uzbekistan from their new bases in northern Afghanistan. Diplomats at the UN say they are being aided and abetted by militant Pakistani groups based, including Lashkar e-Toiba.

Russia's envoy Zamir Kabulov, who has long experience with the Pakistani military's backing of Islamic fundamentalist groups (he served in the Soviet embassy in Kabul in the 1980s), raised this issue with the Pakistani government.

Russia sees itself as the guardian of the Central Asian republics and although it is anxious to see an end to US bases in that region, its resumption of the sole security role in Central Asia will depend on how Pakistan deals with such extremist groups.

If Pakistan can take steps against home-grown extremism, it will do much to convince Russia and China that it deserves help to move out of the American orbit.

But with the long-running political and economic meltdown in Pakistan, there is little chance that the government can act soon.

Nevertheless, a shift in the tectonic plates in the region is taking place. Pakistan and Afghanistan can either take quick advantage of these changes or revert back into chaos.