The history of Peshawar is intertwined with the history of the broader Indian subcontinent. The region was known as Puruṣapura in Sanskrit, literally meaning "city of men". Being among the most ancient cities of the Indian subcontinent, Peshawar had for centuries been a center of trade between West Asia, Central Asia, and the Indian subcontinent.

Ancient history In recorded history, the earliest major city established in the general area of Peshawar was called Puruṣapura (Sanskrit for City of Men), from which the current name "Peshawar" is likely derived and was western capital of Gandhara, after Pushkalavati. Around 700 BCE, the region was governed by the independent Gandhāra Kingdom, which was recognised as a Mahajanapada or "Great Realm". By the 2nd century BCE, Peshawar was an ancient center of learning, as witnessed by the Bakhshali Manuscript, which used the Bakhshali approximation and was found nearby.

The region was annexed by the Persian Achaemenid Empire. Later, the city was invaded by Alexander the Great's army. The city passed into the rule of Alexander's successor, Seleucus I Nicator who ceded it to Chandragupta Maurya, the founder of the Maurya Empire. The fall of the Mauryans provided opportunity to the Indo-Greeks to establish their rule over the region. The Indo-Greek kings combined the Greek and Indian languages and symbols, as seen on their coins, and blended ancient Greek, Hindu and Buddhist religious practices, as seen in the archaeological remains of their cities and in the indications of their support of Buddhism, pointing to a rich fusion of Indian and Hellenistic influences."A vast hoard of coins, with a mixture of Greek profiles and Indian symbols, along with interesting sculptures and some monumental remains from Taxila, Sirkap and Sirsukh, point to a rich fusion of Indian and Hellenistic influences", India, the Ancient Past, Burjor Avari, p.130

The diffusion of Indo-Greek culture had consequences which are still felt today, particularly through the influence of Greco-Buddhist art.Ghose, Sanujit (2011). "Cultural links between India and the Greco-Roman world" . Ancient History Encyclopedia. The Indo-Greeks ultimately disappeared at Peshawar as a political entity around 10 CE following the conquests of the Indo-Scythians, although pockets of Greek populations presumably remained under the subsequent rule of the Indo-Parthians and Kushans."When the Greeks of Bactria and India lost their kingdom they were not all killed, nor did they return to Greece. They merged with the people of the area and worked for the new masters; contributing considerably to the culture and civilization in southern and central Asia." Narain, "The Indo-Greeks" 2003, p.278

The city was then conquered by the Kushan Empire. The Kushan Emperor Kanishka, who ruled from 127 CE, moved the capital from Pushkalavati (present-day Charsadda district, in the Peshawar Valley) to Gandhara (Peshawar city) in the 2nd century CE. Buddhist missionaries arrived at Vedic, and animist Peshawar, seeking counsel with the Kushan rulers. Their teachings were embraced by the Kushans, who converted to Buddhism, assigning the religion with great status in the city. Following this move by the Kushans, Peshawar became a center of Buddhist learning.

The giant Kanishka stupa at Peshawar, which may have been the tallest building in the world at the time, was built by King Kanishka to house Buddhist relics just outside the present-day Ganj Gate of the old city of Peshawar. The Kanishka stupa was said to be an imposing structure, as one traveled down from the Hindu Kush mountains onto the Gandharan plains. The earliest account of the famous building was documented by Faxian, the Chinese Buddhist pilgrim, who was also a monk, who visited the structure in 400 AD and described it as being over 40 chang in height (approximately ) and adorned "with all precious substances". Faxian continued: "Of all the stûpas and temples seen by the travelers, none can compare with this for beauty of form and strength." The stupa was eventually destroyed by lightning, but was repaired several times; it was still in existence at the time of Xuanzang's visit in 634 AD. A jeweled casket containing relics of the Gautama Buddha, and an inscription identifying Kanishka as the donor, existed at the ruined base of this giant stupa — the casket was excavated, by a team supervised by Dr D.B. Spooner in 1909, from a chamber under the very centre of the stupa's base.

Medieval history

The Buddhist, Hindu, and Zoroastrian Pashtuns began converting to Islam following the early annexation by the Arab Empire from Khurasan (in what is Afghanistan, Turkmenistan and northeastern Iran). The Kabul Shahis ruled the Kabul Valley and Gandhara (modern-day Pakistan and Afghanistan) from the decline of the Kushan Empire in the 3rd century to the early 9th century CE. The Shahis are generally split up into two eras: the Buddhist Shahis and the Hindu Shahis, with the change-over thought to have occurred sometime around 870 CE. The kingdom was known as the Kabul Shahan or Ratbelshahan from 565 CE to 670 CE, when the capitals were located in Kapisa and Kabul, and later Udabhandapura, also known as Hund,Sehrai, Fidaullah (1979). Hund: The Forgotten City of Gandhara, p. 2. Peshawar Museum Publications New Series, Peshawar. for its new capital.The Shahi Afghanistan and Punjab, 1973, pp 1, 45–46, 48, 80, Dr D. B. Pandey; The Úakas in India and Their Impact on Indian Life and Culture, 1976, p 80, Vishwa Mitra Mohan – Indo-Scythians; Country, Culture and Political life in early and medieval India, 2004, p 34, Daud Ali.Journal of the Royal Asiatic Society, 1954, pp 112 ff; The Shahis of Afghanistan and Punjab, 1973, p 46, Dr D. B. Pandey; The Úakas in India and Their Impact on Indian Life and Culture, 1976, p 80, Vishwa Mitra Mohan – Indo-Scythians.: The Hindu Shahis, and in the late ninth century great was [their fame] ... in 870 Kabul itself was captured [lost] ... But in the Panjab they consolidated their kingdom and established a new capital first at Hund.

The Hindu Shahis under Jayapala, is known for his struggles in defending his kingdom against the Ghaznavids in the modern-day eastern Afghanistan and Pakistan region. Jayapala saw a danger in the consolidation of the Ghaznavids and invaded their capital city of Ghazni both in the reign of Sebuktigin and in that of his son Mahmud, which initiated the Muslim Ghaznavid and Hindu Shahi struggles. Sebuk Tigin, however, defeated him, and he was forced to pay an indemnity. Jayapala defaulted on the payment and took to the battlefield once more. Jayapala, however, lost control of the entire region between the Kabul Valley and Indus River.

Before Jayapala's struggle began, he had raised a large army of Punjabi Hindus. When Jayapala went to the Punjab region, his army was raised to 100,000 horsemen and an innumerable host of foot soldiers. According to Ferishta:

However, the army was hopeless in battle against the western forces, particularly against the young Mahmud of Ghazni. In the year 1001, soon after Sultan Mahmud came to power and was occupied with the Qarakhanids north of the Hindu Kush, Jayapala attacked Ghazni once more and upon suffering yet another defeat by the powerful Ghaznavid forces, near present-day Peshawar. After the Battle of Peshawar, he committed suicide because his subjects thought he had brought disaster and disgrace to the Shahis.

Jayapala was succeeded by his son Anandapala, who along with other succeeding generations of the Shahis took part in various unsuccessful campaigns against the advancing Ghaznavids but were unsuccessful. The Hindu rulers and vast Hindu population eventually exiled themselves to the Kashmir Siwalik Hills.

Early modern history Pashtun and Mughal rule (1451–1758) Peshawar was a northwestern regional center of the Pashtun Lodi Empire which was founded by Bahlul Lodi in 1451 and centered at Delhi. Peshawar was also incorporated into the Mughal domains by the mid of 16th century. The founder of the Mughul dynasty that would conquer South Asia, Babur, who hailed from the area that is currently Uzbekistan, arrived in Peshawar and founded a city called Bagram, where he rebuilt a fort in 1530 AD.

The Pashtun emperor Sher Shah Suri, who founded the Sur Empire centered at Delhi, turned Peshawar's renaissance into a boom when he ran his Delhi-to-Kabul Shahi Road as a northwestern extension of the Grand Trunk Road through the Khyber Pass and Peshawar in the 16th century. Later Babur's grandson, Akbar the Great, recorded the name of the city as Peshawa, meaning "The Place at the Frontier" or "Near Water" and expanded the bazaars and fortifications. The Muslim technocrats, bureaucrats, soldiers, traders, scientists, architects, teachers, theologians and Sufis flocked from the rest of the Muslim world to the Islamic Sultanate in South Asia, with many settling in the Peshawar region.Caroe, Olaf (1957) The Pathans.

Maratha Peshawar (1758–1759)

The Marathas defeated the Durranis in the Battle of Peshawar in 1758 as a part of Northwest campaign after being invited by Adina Beg, the governor of Punjab. When Raghunathrao, Malhar Rao Holkar and Sikh alliance of Charat Singh and Jassa Singh Ahluwalia left Peshawar, Tukoji Rao Holkar was appointed as the commander of the region. Tukoji along with Khandoji Kadam defeated the Afghan garrison.Third Battle of Panipat by Abhas Verma Bharatiya Kala Prakashan

Durrani Peshawar (1759–1818)

As Mughal power declined in 1747, following a loya jirga, Peshawar would join the Pashtun Durrani Empire of Ahmad Shah Durrani. Peshawar was attacked and captured by the Maratha Empire of western India, which conquered Peshawar on 8 May 1758. A large force of Pashtuns under Ahmad Shah Durrani then re-conquered Peshawar in early 1759.Schofield, Victoria, "Afghan Frontier: Feuding and Fighting in Central Asia", London: Tauris Parke Paperbacks (2003), page 47 Peshawar remained under Durrani rule till the conquest by the Sikhs in 1818.

In 1776, Ahmad Shah's son, Timur Shah Durrani, chose Peshawar as his winter capital and the Bala Hissar Fort in Peshawar was used as the residence of Durrani kings. Pashtuns from Peshawar participated in the incursions of South Asia during the Durrani Empire. Peshawar remained the winter capital until the Sikhs of the Punjab region rose to power in the early nineteenth century.

Sikh conquest (1818–1849) Until 1818, Peshawar was controlled by Afghanistan, but was invaded by the Sikh Empire of Punjab. The arrival of a party led by British explorer and former agent of the East India Company, William Moorcroft was seen as an advantage, both in dealings with Kabul and for protection against the Sikhs of Lahore. Moorcroft continued to Kabul in the company of Peshawari horses and thence to the Hindu Kush. In 1818, Peshawar was captured by Maharaja Ranjit Singh and paid a nominal tribute until it was finally annexed in 1834 by the Sikhs, after which the city fell into steep decline. Many of Peshawar's famous Mosques and gardens were destroyed by the Sikhs at this time. An Italian was appointed by the Sikhs as administrator. Acting on behalf of the Sikhs, Paolo Avitabile, unleashed a reign of fear – his time in Peshawar is known as a time of "gallows and gibbets." The city's famous Mahabat Khan, built in 1630 in the Jeweler's Bazaar, was badly damaged and desecrated by the Sikh conquerors.