After the murder of Alamgir II, his son Ali Gauhar succeeded him by taking the title of Shah Alam. Emperor Shah Alam was an ornamental figurehead with the reigns of government actually under the control of his Wazir, Ghazi-ud-Din.
Ghazi-ud-Din by his deceitful dealings had created around him a host of enemies, and in order to defeat them he sided with the Marhattas. During the reign of Alamgir II in 1758, the Marhattas had occupied Lahore and deposed Timur Shah who had been appointed a year earlier as viceroy by his father, Ahmad Shah Abdali. In August 1759, the Afghan monarch Ahmad Shah Abdali entered India. It took him almost two years to deal a fatal blow to Marhattas in the third battle of Panipat, fought on June 14, 1761. Consequently, the power of the Marhattas was crushed and their imperialistic dream of setting up a Marhatta Empire was shattered once and for all.
After the battle of Panipat, Ahmed Shah Abdali left the throne of Delhi to Shah Alam with Najib-ud-Daula as his Wazir. From 1761 to 1771, the capital was without a king. Shah Alam, after his unsuccessful effort to defeat the British in the Battle of Buxar in 1764, was taken in as the prisoner and did not return to Delhi till 1772. By giving the Diwani of Bengal, Bihar and Orrisa to the East India Company, Shah Alam further strengthened British control over the Indian Sub-continent. After the death of Najib-ud-Daula, Shah Alam remained a puppet in the hands of the ministers and the Marhattas. He appointed Sindhia, a Marhatta leader, as in-charge of the administration of Delhi.
In an expedition against Dabitah Khan, who was earlier appointed as Mir Bakhshi by Shah Alam, the entire family of Dabitah Khan and other Rohilla leaders were arrested and severely humiliated. Among them was Dabitah’s son, Ghulam Qadir Rohilla, who was castrated and made to serve as a page in the palace. In September 1787, Ghulam Qadir Rohilla