The United States gained the territory of Florida as Andrew Jackson attacked and captured Spanish forts, claiming Florida for the United States. Monroe signed a treaty with the Spanish which gave Florida to the United States.
Although Florida officially remained under Spanish sovereignty until 1821 as part of the General Captaincy of Cuba, it did not totally dominate the territory because of the independence tendencies of its inhabitants, either because they were British ex-colonies, or because during the period of the French intervention in the Iberian Peninsula between 1808 and 1814 had been influenced by French revolutionary ideas and, on the other hand, due to the enormous resources that the Spanish required to expel the largest army of that time.
In small West Florida, the Spanish had to evacuate their troops from Mabila (now called Mobile, in the current state of Alabama) in April 1813 to the capital Pensacola and the United States seized the city in the context of the War of 1812, claiming it as part of the Louisiana Purchase from the French a few years before.
Faced with the precarious situation of Eastern Florida, on June 29, 1817, General MacGregor took Fort San Carlos, located on Amelia Island on the northeastern coast of Florida, at 35 miles north of Vacapilatca (today Jacksonville) on the border with Georgia. Days later, Floridian insurgents north of Vacapilatca called the population to proclaim the independence of Spain and declare the "Republic of Florida", establishing its capital in the fortified town of Fernandina.
Under the orders of the French corsair Luis Aury, a fleet was organized that actively participated in the events that resulted in the creation of the nation of Florida, militarizing the coast before an inevitable Spanish invasion from Havana.
Taking advantage of these events, US President James Monroe and his Secretary of State, John Quincy Adams, ordered a maritime and land operation to appropriate Florida. In September 1817, a large US military deployment supported by Spanish troops from Havana landed in Amelia and from there went to Fernandina to subdue the rebels with blood and fire, capturing the authorities who defended the insurgency in Florida.
In 1818, Andrew Jackson invaded East Florida in what US history called the First Seminole War and this fact earned him popular support in the country and that of the Government, being Monroe President and Secretary of State John Quincy Adams, who, with the Adams-Onis treaty of 1819, forced a weakened Spain to deliver what remained of its colonial territory in exchange for five million dollars.
The US annexation of the territory finally ended in 1821 when the liberal government that had overthrown Ferdinand VII ratified the treaty. That year marked the intensification of the war against the Seminole tribes that inhabited the peninsula to establish American colonists and conform what is today the southernmost state of the United States of America.