The history of Pakistan preceding the country's independence in 1947 is shared with that of Afghanistan, India, and Iran. Spanning the western expanse of the Indian subcontinent and the eastern borderlands of the Iranian plateau, the region of present-day Pakistan served both as the fertile ground of a major civilization and as the gateway of South Asia to Central Asia and the Near East.
Situated on the first coastal migration route of Homo sapiens out of Africa, the region was inhabited early by modern humans. The 9,000-year history of village life in South Asia traces back to the Neolithic (7000–4300 BCE) site of Mehrgarh in Pakistan, and the 5,000-year history of urban life in South Asia to the various sites of the Indus Valley Civilization, including Mohenjo Daro and Harappa.
Following the decline of the Indus valley civilization, Indo-Aryan tribes moved into the Punjab from Central Asia in several waves of migration in the Vedic Period (1500–500 BCE), bringing with them came their distinctive religious traditions and practices which fused with local culture. The Indo-Aryans religious beliefs and practices from the Bactria–Margiana culture and the native Harappan Indus beliefs of the former Indus Valley Civilisation eventually gave rise to Vedic culture and tribes. Most notable among them was Gandhara civilization, which flourished at the crossroads of India, Central Asia, and the Middle East, connecting trade routes and absorbing cultural influences from diverse civilizations. The initial early Vedic culture was a tribal, pastoral society centred in the Indus Valley, of what is today Pakistan. During this period the Vedas, the oldest scriptures of Hinduism, were composed.
The ensuing millennia saw the region of present-day Pakistan absorb many influences—represented among others in the ancient, mainly Hindu-Buddhist, sites of Taxila, and Takht-i-Bahi, the 14th-century Islamic-Sindhi monuments of Thatta, and the 17th-century Mughal monuments of Lahore.