One of the earliest Pashtun nationalists was the 16th-century revolutionary leader Bayazid Pir Roshan from Waziristan. Another early Pashtun nationalist was the 17th-century "warrior-poet" Khushal Khan Khattak, who was imprisoned by the Mughal emperor Aurangzeb for trying to incite the Pashtuns to rebel against the rule of the Mughals. However, despite sharing a common language and believing in a common ancestry, the Pashtuns first achieved unity in the 18th century after being under foreign rule for many centuries. The eastern parts of Pashtunistan was ruled by the Mughal Empire, while the western parts were ruled by the Persian Safavids as their easternmost provinces. During the early 18th century, Pashtun tribes led by Mirwais Hotak successfully revolted against the Safavids in the city of Kandahar. In a chain of events, he declared Loy Kandahar and other parts of what is now southern Afghanistan independent. By 1738 the Mughal Empire had been crushingly defeated and their capital sacked and looted by forces of a new Iranian ruler; the military genius and commander Nader Shah Afshar. Besides Persian, Turkmen, and Caucasian forces, Nader was also accompanied by the young Ahmad Shah Durrani and 4,000 well-trained Pashtun troops.