LONDON — Nuclear-armed Pakistan is a key ally of the United States — but the relationship is far from untroubled. And one of Washington's main geopolitical rivals appears ready to step in.

The Pentagon is warning that the Islamic republic may soon house a Chinese military base.

Pakistan's Chief of Naval Staff Admiral Muhammad Zakaullah salutes China's People's Liberation Army marines upon their arrival in Karachi, Pakistan, on June 10. Pakistan Navy via Twitter

While the U.S. gives Islamabad hundreds of millions of dollars in aid, the two countries are not on the same page when it comes to fighting terrorism or ending the war in Afghanistan.

A report released earlier this month suggested that Beijing would likely turn to countries such as Pakistan as it seeks to project its economic and military power abroad.

The Pentagon didn't provide a time frame for such a move. However, a senior Pakistani diplomat confirmed to NBC News that his country invited China to build a naval facility on its territory back in 2011.

"What better way for China to demonstrate clout than to build a military base right in your rival's backyard?"

Speaking on the condition of anonymity, the diplomat said this request came just days after U.S. Navy SEALs conducted a secret raid to kill Osama bin Laden in the Pakistani city of Abbottabad, when relations between Washington and Islamabad took a nosedive.

Despite the reports, China's Foreign Ministry Spokesperson Hua Chunying dismissed the idea of a Chinese base in Pakistan as "conjecture" and "irresponsible remarks."

But Western experts and Pakistani officials see it as a distinct possibility.

Shifting Ties

Soon after 9/11, Washington and Islamabad drew closer. The U.S. lavished Pakistan with military and civilian aid, and in return Pakistan granted the U.S. forward bases for military operations in Afghanistan and drone strikes in its own tribal areas.

But more recently Pakistan has become more estranged from the U.S. and the West because of continued allegations that it harbors militant groups. It's also accused of not doing everything it can to bring the Taliban to the negotiating table over the war in Afghanistan.

In addition, Western countries are more interested in doing business with India, which is Pakistan's arch-rival and a regional strategic competitor to China.

Where the West has withdrawn, China has stepped in.

China's "Belt and Road" plan would be the world's largest infrastructure program. Paul Cheung / NBC News

Pakistan is set to play an important role in China's "Belt and Road," a $1.4-trillion global trade plan that analysts say could shift the center of global economy and challenge the current U.S.-led order.

Islamabad is banking on receiving more than $50 billion in Chinese loans and grants in relation to this initiative. Its part of the trade route — known as the China Pakistan Economic Corridor, or CPEC — would connect the landlocked Chinese province of Xinjiang to the Indian Ocean and some of the world's most important maritime corridors.

Common Enemy

The Chinese-Pakistan alliance also makes sense in terms of their shared rivalry with India.

"What better way for China to demonstrate clout than to build a military base right in your rival's backyard?" said Michael Kugelman, a senior associate at the Wilson Center.

All three countries have nuclear weapons, and some experts have long since worried that ongoing skirmishes between India and Pakistan could one day boil over into a nuclear war — although this remains a worst-case-scenario.

Related: $46B Project Reveals Chinese Power Play in Pakistan

Because Pakistan has a smaller conventional army than India's, a Chinese base on its soil could help the Islamic republic compete with its old Hindu rival.

"We need an equalizer against India … Previously, it was the U.S. and Saudi [Arabia]. Now, it's China," one Pakistani intelligence official said, speaking on condition of anonymity.

Chinese warships arrive in Karachi, Pakistan, on June 10. Pakistan Navy via Twitter

China has already riled the U.S. and its allies after constructing several man-made islands on reefs and rock formations in the disputed South China Sea.

With overlapping territorial claims from China, Vietnam, Malaysia, and the Philippines, this body of water is home to rich energy and fishing reserves and around $5 trillion of sea-borne trade passes through it each year.

Pakistan's role in China's global trade plans means a military base would make sense. The Chinese "may have strong incentives to protect their assets," said Sameer Lalwani, a research fellow at the Stimson Center, a think tank based in Washington.

"Chinese deployments in Pakistan could range from Chinese intelligence personnel, naval forces in ports like Gwadar, air forces to support missions in Central Asia, or even special forces or counterterrorism strike capabilities," he said.

A map showing the location of Gwadar, Pakistan. Google Maps

Gwadar already has a commercial port built and operated by Chinese authorities and was touted by one high-ranking Pakistani military official as a possible site for the Chinese base. The other two potential locations are Jiwani and Ormara.

All three are close to the vital Strait of Hormuz and the Persian Gulf.

Signs of Strain

Even though China calls Pakistan its "Iron Brother" and "All Weather Friend," Beijing's patience has also been tested. Last week, ISIS claimed that it killed two Chinese teachers who were abducted in Balochistan in May.

Such incidents have prompted Pakistan to beef up security around Chinese citizens involved in the infrastructure splurge. The army has raised two new infantry divisions, speckled with commando, paramilitary and police units, to protect Chinese workers.

Related: China's 'Money Game' Woos Allies Away from Neighbor

As a show of force and unity, three Chinese warships docked on Saturday for a training mission at the Pakistani port of Karachi, where China is already manufacturing four attack submarines as part of a larger arms deal.

But there are other sensitivities involved.

"There is a firm opinion against any bases being given to any foreign country inside Pakistan. We've seen what happened when we gave such rights to the Americans," said Lt. General Javed Ashraf, retired chief of the Inter-Services Intelligence Directorate, the country's intelligence agency known as the ISI. "This is not only what the general public feels, but the Pakistani forces are also opposed to the idea."

Wajahat S. Khan and Alexander Smith reported from London. Eric Baculinao reported from Beijing.