The Portuguese were ousted by the Dutch East India Company, who during the conflicts between the Kozhikode and the Kochi, gained control of the trade.[123] They lost to Dutch at Quilon after 1661 and later, the Portuguese left south-western coast.[124] The arrival of British on Malabar Coast can be traced back to the year 1615, when a group under the leadership of Captain William Keeling arrived at Kozhikode, using three ships.[60] It was in these ships that Sir Thomas Roe went to visit Jahangir, the fourth Mughal emperor, as British envoy.[60] In 1664, the municipality of Fort Kochi was established by Dutch Malabar, making it the first municipality in Indian subcontinent, which got dissolved when the Dutch authority got weaker in 18th century.[125] The Dutch in turn were weakened by constant battles with Marthanda Varma of the Travancore Royal Family, and were defeated at the Battle of Colachel in 1741.[126] An agreement, known as "Treaty of Mavelikkara", was signed by the Dutch and Travancore in 1753, according to which the Dutch were compelled to detach from all political involvement in the region.[127][128][129] In the 18th Century, Travancore King Sree Anizham Thirunal Marthanda Varma annexed all the kingdoms up to Cochin through military conquests, resulting in the rise of Travancore to pre-eminence in Kerala.[130] The Kochi ruler sued for peace with Anizham Thirunal and the northern and north-central parts of Kerala (Malabar District), along with Fort Kochi, Tangasseri, and Anchuthengu in southern Kerala, came under direct British rule until India became independent.[131][132] Travancore became the dominant state in Kerala by defeating the powerful Zamorin of Kozhikode in the battle of Purakkad in 1755.[133]