Apart from the disastrous invasion by the Afsharid ruler of Iran, Nader Shah in 1739, the Mughals were successfully contested by the Marathas.
However, usurpers from the Woodeyar rajas such as Hyder Ali who began as an administrator and his son Tipu Sultan transformed the kingdom and westernized the army & it soon turned into a military threat both to the British and the Marathas.
[6] After the Second Anglo-Mysore War, the son and successor of Hyder Ali the new ruler of Mysore Tipu Sultan, sought to keep offensive moves by the Marathas at bay.
The Maratha had established a military alliance with the ruler of Hyderabad with a common purpose of recovering territories both sides had lost to Mysore during previous conflicts.
The Marathas also attempted to draw the British East India Company into the pending conflict, but a neutrality policy implemented by the new governor-general, Lord Charles Cornwallis made its participation difficult.
The Maratha-Mysore War ended after the final conflict during Mysore's successful siege of Bahadur Benda in January 1787, and the Marathas settled for peace with the kingdom of Mysore, to which Tipu Sultan obliged being weary of a pyrrhic campaign against the Marathas ,with the signing of the treaty of Gajendragad in April 1787.