Third Battle of Panipat Main article: Third Battle of Panipath
The Mughal power in northern India had been declining since the reign of Aurangzeb, who died in 1707; In 1751-52, Ahamdiya treaty was signed between the Marathas and Mughals, when Balaji Bajirao was the Peshwa. Through this treaty, the Marathas controlled virtually the whole of India from their capital at Pune and Mughal rule was restricted only to Delhi (the Mughals remained the nominal heads of Delhi). Marathas were now straining to expand their area of control towards the Northwest of India. Ahmad Shah sacked the Mughal capital and withdrew with the booty he coveted. To counter the Pashtuns, Peshwa Balaji Bajirao sent Raghunathrao. He succeeded in ousting Timur Shah and his court from India and brought Lahore, Multan, Kashmir and other subahs on the Indian side of Attock under Maratha rule. Thus, upon his return to Kandahar in 1757, Ahmad was forced to return to India and face the formidable attacks of the Maratha Confederacy.
Ahmad Shah declared a jihad (or Islamic holy war) against the Marathas, and warriors from various Pashtun tribes, as well as other tribes such as the Baloch, Tajiks, and Nawabs in India, answered his call. Early skirmishes were followed by victory for the Pashtuns against the smaller Maratha garrisons in Northwest India and by 1759 Ahmad and his army had reached Lahore and were poised to confront the Marathas. By 1760, the Maratha groups had coalesced into a big enough army under the command of Sadashivrao Bhau. Once again, Panipat was the scene of a confrontation between two warring contenders for control of northern India. The Third Battle of Panipat (January 1761), fought between largely Muslim and largely Hindu armies was waged along a twelve-kilometer front. Despite decisively defeating the Marathas, what might have been Ahmad Shah's peaceful control of his domains was disrupted by other challenges.
Zaman Shah (1793-1801)Main article: Zaman Shah Durrani
After the death of Timur Shah, three of his sons, the governors of Kandahar, Herat and Kabul, contended for the succession. Zaman Shah, governor of Kabul, held the field by virtue of being in control of the capital, and became shah at the age of twenty-three. Many of his half-brothers were imprisoned on their arrival in the capital for the purpose, ironically, of electing a new shah. The quarrels among Timur's descendants that threw Afghanistan into turmoil also provided the pretext for the intervention of outside forces.
The efforts of the Sadozai heirs of Timur to impose a true monarchy on the truculent Pashtun tribes, and their efforts to rule absolutely and without the advice of the other major Pashtun tribal leaders, were ultimately unsuccessful. The Sikhs became particularly troublesome, and after several unsuccessful efforts to subdue them, Zaman Shah made the mistake of appointing a forceful young Sikh chief, Ranjit Singh, as his governor in the Punjab. This "one-eyed" warrior would later become an implacable enemy of Pashtun rulers in Afghanistan.
Zaman's downfall was triggered by his attempts to consolidate power. Although it had been through the support of the Barakzai chief, Painda Khan Barakzai, that he had come to the throne, Zaman soon began to remove prominent Barakzai leaders from positions of power and replace them with men of his own lineage, the Sadozai. This upset the delicate balance of Durrani tribal politics that Ahmad Shah had established and may have prompted Painda Khan and other Durrani chiefs to plot against the shah. Painda Khan and the chiefs of the Nurzai and the Alizai Durrani clans were executed, as was the chief of the Qizilbash clan. Painda Khan's son fled to Iran and pledged the substantial support of his Barakzai followers to a rival claimant to the throne, Zaman's older brother, Mahmud Shah. The clans of the chiefs Zaman had executed joined forces with the rebels, and they took Kandahar without bloodshed