The Portuguese took advantage of the rivalry between the Zamorin and the King of Kochi allied with Kochi. When Francisco de Almeida was appointed as Viceroy of Portuguese India in 1505, his headquarters was established at Fort Kochi (Fort Emmanuel) rather than in Kozhikode. During his reign, the Portuguese managed to dominate relations with Kochi and established a few fortresses on the Malabar Coast. Fort St Angelo or St. Angelo Fort was built at Kannur in 1505 and Fort St Thomas was built at Kollam(Quilon) in 1518 by the Portuguese. However, the Portuguese suffered setbacks from attacks by Zamorin forces in Malabar region; especially from naval attacks under the leadership of Kozhikode admirals known as Kunjali Marakkars, which compelled them to seek a treaty. The Kunjali Marakkars are credited with organizing the first naval defense of the Indian coast. An insurrection at the Port of Quilon between the Arabs and the Portuguese led to the end of the Portuguese era in Quilon. In 1571, the Portuguese were defeated by the Zamorin forces in the battle at Chaliyam Fort. The Muslim line of Ali Rajas of Arakkal kingdom, near Kannur, who were the vassals of the Kolathiri, ruled over the Lakshadweep islands.