Pakistan and China established diplomatic relations in 1947 after Pakistan gained independence. However, they could not become strong allies initially due to Pakistan's alliance with the US and China being a communist state. Relations strengthened in the 1960s as China supported Pakistan in its territorial disputes with India and provided economic assistance. China also aided Pakistan militarily during its wars with India in 1965 and 1971. Cooperation between the two countries continued to grow in subsequent decades, including the building of the Karakoram Highway connecting them and increased nuclear cooperation.