In 1739 Nadir Shah attacked Pakistan and after defeating the Mughal Emperor Mohammed Shah (Rangeela) claimed Punjab (from Lahore westward), the North-West Frontier Province, Balochistan and Sind as provinces of his Empire. Upon the death of Nadir Shah one of his generals, a Pashtun named Ahmed Shah Abdali (who late changed his name to Ahmad Shah Durrani) established the kingdom of Afghanistan in 1747 and made Pakistan part of his newly created state. He claimed Kashmir, Peshawar, Daman, Multan, Sindh and Punjab up to the Sutlej.
When the Abdali kingdom weakened early in the 19th century due to internecine warfare, the Abdali kingdom began to decline and an independent kingdom arose in Punjab headed by the Sikh leader Ranjit Singh. The British who had established their control over Delhi in 1803 warned Ranjit Singh not to try to impose his authority on the Sikh Sardars of East Punjab i.e., beyond Sutlej. As for Sind, from as early as the last days of Aurangzeb, it had begun to assert its independence and a succession of semi-independent dynasties under the Daudpotas, Kalhoras and Talpurs continued to rule over this province till British conquest in 1843 AD Meanwhile, Balochistan came under the sway of the Khan of Kalat with a few coastal cities such as Gwadar coming under the control of the Sultan of Oman.
Sikh warrior Ranjit Singh defeated the Afghans and took the title of Maharaja (High King) of the Punjab and eventually sovereign of the Sikh empire, stretching from within the shadows of Delhi to beyond Peshawar, with his capital at Lahore. It was also the last territory of South Asia to fall to the British Empire mainly due to the betrayal by its top Dogra Generals, during the two bloody Anglo-Sikh wars in 1845-6 and 1848-49. The outcome was a very narrow victory for the British resulting in the annexation of the Punjab and the fall of Sikh rule.
The two Anglo-Afghan wars that involved Pakistan directly took place in 1839 and again in 1842 and 1878 and resulted in the eventual loss of Pashtun/Afghan territory to the expanding British Indian empire. Following the 2nd Anglo-Afghan war, a tenuous peace resulted between Afghanistan and the British empire based in India. Decades later, Pakistan would come to be annexed by the British.
For Afghan ruler Abdur Rahman Khan, delineating the boundary with India (through the Pashtun area) was far more significant, and it was during his reign that the Durand Line was drawn. Under pressure, Abdur Rahman agreed in 1893 to accept a mission headed by the British Indian foreign secretary, Sir Mortimer Durand, to define the limits of British and Afghan control in the Pashtun territories. Boundary limits were agreed on by Durand and Abdur Rahman before the end of 1893, but there is some question about the degree to which Abdur Rahman willingly ceded certain regions. There were indications that he regarded the Durand Line as a delimitation of separate areas of political responsibility, not a permanent international frontier, and that he did not explicitly cede control over certain parts (such as Kurram and Chitral) that were already in British control under the Treaty of Gandamak.
The Durand Line cut through both tribes and villages and bore little relation to the realities of topography, demography, or even military strategy. The line laid the foundation, not for peace between the border regions, but for heated disagreement between the governments of Afghanistan and British India, and later, Afghanistan and Pakistan. The issue revolves around the Pashtun nationalist movement known as Pashtunistan.
During much of the 19th century, the British and Russian Empires engaged in what came to be known as the Great Game as both sides intrigued over Afghanistan and western Pakistan. Often arming local Pashtun and Tajik tribesmen, both sides sought to undermine the other, while the rulers of Afghanistan were able to maintain some measure of independence in-spite of the loss of territories to the east to British Raj.