The history of the Philippines from 1565 to 1898 is known as the Spanish colonial period, during which the Philippine Islands were ruled as the Captaincy General of the Philippines within the Spanish East Indies, initially under the Viceroyalty of New Spain, based in Mexico City, until the independence of the Mexican Empire from Spain in 1821. This resulted in direct Spanish control during a period of governmental instability there. The Philippines was under direct royal governance from 1821 to 1898.
The first documented European contact with the Philippines was made in 1521 by Ferdinand Magellan in his circumnavigation expedition, during which he was killed in the Battle of Mactan. Forty-four years later, a Spanish expedition led by Miguel López de Legazpi left modern Mexico and began the Spanish conquest of the Philippines. Legazpi's expedition arrived in the Philippines in 1565, during the reign of Philip II of Spain, whose name has remained attached to the country.