The Captaincy General of the Philippines (Capitanía General de Filipinas kapitaˈni.a xeneˈɾal de filiˈpinas; Kapitaniya Heneral ng Pilipinas) was an administrative district of the Spanish Empire in Southeast Asia governed by a governor-general as a dependency of the Viceroyalty of New Spain based in Mexico City until Mexican independence when it was transferred directly to Madrid. The Captaincy General encompassed the Spanish East Indies, which included among others the Philippine Islands, the Mariana Islands, and the Caroline Islands. It was founded in 1565 with the first permanent Spanish forts. For centuries, all the administrative, political and economic aspects of the Captaincy General were administered in Mexico City by the Viceroyalty of New Spain for the Spanish Crown. However, in 1821, following the independence of the Mexican empire, all control was transferred to Madrid. It was succeeded by the short-lived First Philippine Republic following its independence through the Philippine Revolution. History of the Philippines (1565–1898) Spanish East Indies After a long, tolling voyage across the Pacific Ocean, Ferdinand Magellan reached the island of Guam on 6 March 1521 and anchored the three ships that were left of his fleet in Umatac Bay, before proceeding to the Philippines, where he met his death during the Battle of Mactan. Antonio Pigafetta, the expedition's chronicler and one of only 18 original crew members to survive Ferdinand Magellan's circumnavigation of the globe, recorded all details of the voyage. Miguel López de Legazpi arrived in Umatac in 1565 and claimed the island of Guam for Spain, before proceeding to the Philippines, where, in a short period of time, they successfully incorporated into Spain's empire Cebu, Samar, Mazaua, Leyte, and Bohol, before conquering Manila. Later (in 1569), Miguel López de Legazpi transferred the Spanish headquarters from Cebu to Panay, where they found allies, who were never conquered by Spain but were accomplished as vassals by means of pacts, peace treaties, and reciprocal alliances.