There had been Hindu–Muslim clashes during the medieval period, notably when Muslim armies from Mysore invaded and gained control of northern Kerala in 1766. The Nairs of Kottayam and Kadathanad led the resistance, and the Nairs managed to defeat all Mysorean garrisons except for those in Palakkad. Shortly afterwards, Haider Ali died and his son Tipu had become Sultan. The Nairs of Calicut and South Malabar had recaptured Calicut and defeated an army sent by Tipu to break the siege. This had caused the Sultan himself to intervene in 1789 during which many Hindus, especially Nairs, were kept captive or killed by Muslims under Tipu Sultan. Many Nairs had fled to the protection of Travancore, while others engaged in guerilla warfare. However the Nairs of Travancore were able to defeat the Muslim forces in 1792 at the Third Anglo-Mysore War. After this, the East India Company established its pre-eminence throughout the entire Kerala region.