China moved to shore up ties with Afghanistan on Friday, signing a joint declaration pledging wide-ranging cooperation and laying the groundwork for enhanced influence with Kabul after the departure of most foreign troops at the end of 2014.

The declaration was issued following talks in Beijing between Chinese President Hu Jintao and his Afghan counterpart, Hamid Karzai, at which Hu pledged to provide "sincere and selfless help to the Afghanistan side." It calls for closer cooperation in areas ranging from border security to disease control.

"At present, Afghanistan has entered into a critical transition period," Hu told Karzai at their meeting at the Great Hall of the People in central Beijing. "China is a trustworthy neighbor and friend of Afghanistan."

The sides agreed to exchange intelligence and strengthen cooperation against terrorism, illegal immigration, illegal arms and drug trafficking, according to a text released by China's Foreign Ministry.

China firmly supports Afghanistan's efforts in combating terrorism and drug trafficking and safeguarding national stability, the declaration said. The sides also promised to cooperate in fighting infectious diseases, in disaster prevention and mitigation, and in other "nontraditional security areas," it said.

Afghanistan reiterated its support for China in combating terrorism, extremism and separatism — Beijing's standard term for Muslim ethnic Uighurs (pronounced WEE'-gurs) seeking independence for the far western region of Xinjiang. The government also pledged to take "tangible measures" to protect Chinese citizens and institutions in Afghanistan.

Karzai had earlier attended the annual summit of the Shanghai Cooperation Organization, a Russian- and Chinese-dominated regional security bloc. Afghanistan became an observer state of the group on Thursday.

Including Afghanistan in the group is one way in which China is positioning itself for a bigger role in the impoverished, war-torn country, with which it shares a narrow sliver of border high in the Karakoram mountain range.

In December, China's state-owned National Petroleum Corp. signed a deal allowing it to become the first foreign company to exploit Afghanistan's oil and natural gas reserves. Three years earlier, the China Metallurgical Construction Co. signed a contract to develop the Aynak copper mine in Logar province. Beijing's $3.5 billion stake in the mine is the largest foreign investment in Afghanistan.

Afghan officials hope vast untapped mineral deposits valued by the U.S. Defense Department at $1 trillion will help offset the loss of foreign aid once foreign troops withdraw.

In Friday's declaration, China also committed to a 150 million yuan ($23.8 million) grant to the Afghan government for 2012 and said the sides would explore new ways to boost trade and investment. Infrastructure development, engineering and agriculture were also mentioned as areas to focus on, alongside resource exploitation.