Pakistan's quick response to charges by China that militants involved in attacks in Xinjiang had trained on its soil shows the importance of its ties with Beijing, but it could be a mistake for Islamabad if it relies too much on China.
Pakistan immediately dispatched Lieutenant-General Ahmed Shuja Pasha, director general of Pakistan's powerful Inter-Services Intelligence (ISI) spy agency, to Beijing after Islamic militants mounted a weekend attack that left 11 people dead in the western region of Xinjiang, according to media reports.
While the ISI declined to confirm the trip, Western diplomats and Pakistani analysts agreed that the attacks would likely be at the top of any agenda.
"We cannot allow Pakistani territory to be used for any activities against any neighbor, especially a close ally like China," said Mushahid Hussain Sayed, Chairman of the Pakistan-China Institute.
"There are strong ties between Pakistan and China, and we are cooperating closely on this issue."
Pasha's speedy trip was a clear sign of Pakistan's priorities.
The United States rarely gets that level of cooperation when it presses Pakistan on militants operating in its border regions. American officials for years said al Qaeda leader Osama bin Laden, killed in a U.S. raid in Pakistan in May, was hiding in the country.
Pakistan often responded with demands for specific, actionable intelligence before it would consider investigating.
Islamabad makes no secret of its preference for China over the United States as a military patron, calling Beijing an "all-weather" ally in contrast to Washington's supposedly fickle friendship.
The Pakistani foreign ministry issued a statement on Monday extending "full support" to China.
China is a major investor in predominantly Muslim Pakistan in areas such as telecommunications, ports and infrastructure. The countries are linked by a Chinese-built road pushed through Pakistan's northern mountains.
Trade with Pakistan is worth almost $9 billion a year for Pakistan, and China is its top arms supplier.
But all that matters only up to a point.
"Pakistan wants to play its own game by creating a front against the United States," said Hasan Askari-Rizvi, an independent political analyst.
"That will not happen. ... Now China has the same complaint which the United States has with Pakistan."
Barry Sautman, a professor at Hong Kong University of Science and Technology, said that China, like the United States, wanted Pakistan to help it control Islamist militancy. But it is frustrated by the chaotic nature of Pakistani governance, and its inability to control militants or militant-friendly elements in its security agencies.
"I would think the Chinese government would want to have its military and security apparatus liaise with Pakistani authorities to come up with a common plan, but the U.S. found that very difficult to do," he said. "And I am sure China will find it difficult as well."
Furthermore, Pakistan's usefulness to China is only in South Asia, where it competes with India. But China has global ambitions; it is unlikely to sacrifice them for an ally that has proved a headache to the United States, which has its own deep relationship with China.
"Being seen to take a provocative stand alongside Pakistan comes at a substantial cost, but provides little strategic benefit," Urmila Venugopalan, an independent analyst and former Asia editor at Jane's Intelligence Review, wrote last month in Foreign Policy.
China, he wrote, does not want to push India deeper into the American orbit.
"An escalation in Chinese aid to Pakistan would surely antagonize India, creating a new point of friction in the triangular relationship between Beijing, New Delhi, and Washington."
China has also shown no sign that it is willing to shoulder some of the financial burden of propping up Pakistan that the United States has so far been willing to bear.
In 2008, when Pakistan was suffering a balance of payments crisis and sought China's support to avoid turning to the International Monetary Fund and its restrictive terms on a $7.5 billion loan, China provided only $500 million.
China may share concerns over Pakistan's stability, Venugopalan writes, "but it has preferred to let Americans bear the costs of improving the country's security".
Pakistan's attempts to play China off the United States will ultimately backfire, analysts say. Although important, Pakistan is not the most important issue for Beijing and Washington.
"It is our misunderstanding if we think that we will team up with China if we are pressed by the United States," Rizvi said. "China and the United States have their own relations and they cannot compromise them for the sake of Pakistan."