Shah Alam faced many invasions, mainly by the Emir of Afghanistan, Ahmed Shah Abdali, which led to the Third Battle of Panipat between the Maratha Empire, who maintained suzerainty over Mughal affairs in Delhi and the Afghans led by Abdali. In 1760, the invading forces of Abdali were driven away by the Marathas, led by Sadashivrao Bhau, who deposed Shah Jahan III, the puppet Mughal emperor of Feroze Jung III, and installed Shah Alam II as the rightful emperor under Maratha control.