Answer by taking a quote from the following article:

The overseas expansion under the crown of Castile was initiated under the royal authority and first accomplished by the Spanish conquistadores. The Americas were incorporated into the Spanish Empire, with the exception of Brazil and Canada, and the crown created civil and religious structures to administer the region. The motivations for colonial expansion were trade and the spread of the Catholic faith through indigenous conversions. Beginning with the 1492 arrival of Christopher Columbus in the Caribbean and continuing control of vast territory for over three centuries, the Spanish Empire would expand across the Caribbean Islands, half of South America, most of Central America and much of North America (including present day Mexico, Florida and the Southwestern and Pacific Coastal regions of the United States).

During the Napoleonic Peninsular War in Europe between France and Spain, assemblies called juntas were established to rule in the name of Ferdinand VII of Spain. The Libertadores (Spanish and Portuguese for "Liberators") were the principal leaders of the Spanish American wars of independence. They were predominantly criollos (Americas-born people of European ancestry, mostly Spanish or Portuguese), bourgeois and influenced by liberalism and in some cases with military training in the mother country. In 1809 the first declarations of independence from Spanish rule occurred in the Viceroyalty of New Granada. The first two were in present-day Bolivia at Sucre (May 25), and La Paz (July 16); and the third in present-day Ecuador at Quito (August 10). In 1810 Mexico declared independence, with the Mexican War of Independence following for over a decade. In 1821 Treaty of Cordoba established Mexican independence from Spain and concluded the War. The Plan of Iguala was part of the peace treaty to establish a constitutional foundation for an independent Mexico. These began a movement for colonial independence that spread to Spain's other colonies in the Americas. The ideas from the French and the American Revolution influenced the efforts. All of the colonies, except Cuba and Puerto Rico, attained independence by the 1820s. The British Empire offered support, wanting to end the Spanish monopoly on trade with its colonies in the Americas. In 1898, the United States achieved victory in the Spanish-American War with Spain, ending the Spanish colonial era. Spanish possession and rule of its remaining colonies in the Americas ended in that year with its sovereignty transferred to the United States. The United States took occupation of Cuba, the Philippines, and Puerto Rico. Puerto Rico continues to be a possession of the United States, now officially continues as a self-governing unincorporated territory.

What happened in the 19th Century?
In 1809 the first declarations of independence from Spanish rule occurred in the Viceroyalty of New Granada.