The events of the French Revolution at the end of the 18th century had a profound effect on Spain.
During the reign of Carlos IV Spain declared war to revolutionary France, but the prime minister Godoy established good relations with France under Napoleon.
In this context, Spain joined Napoleon in his war against Great Britain (defeat at the Battle of Trafalgar, 1805) and against Portugal (sign of the Treaty of Fontainebleau, 1807).
With the pretext of this treaty, Napoleon began the occupation of Spain.
He moved the royal family to Bayona after a popular revolt against Godoy (Mutiny of Aranjuez, 1808) and crowned his brother as José I Bonaparte (Abdications of Bayona, 1808).
In 3 May 1808, the people of Madrid rose up in arms against the French and were then suppressed.
In response to this event, a patriotic feeling spread across the country and the War of the Spanish Independence started in 3 May 1808 and lasted until 1814.
The majority of the Spanish population considered Fernando VII, son of Carlos IV, as the legitimate king, while a minority, mainly composed of intellectuals, supported the new monarchy of José I.
Despite suffering his first defeat on an open field (Bailén, 1808)
The Spanish were forced to use guerrilla war to weaken the invaders and had the military support of Green Britain.
Finally, the French troops were defeated and Napoleon signed the Treaty of Valençay in 1813, in which he recognised Fernando VII as King of Spain and the Indies.
In 1810, in the middle of the conflict, Cortes were summoned in Cádiz to direct the war effort against the French.
The liberals were able to dominate them against the absolutists, and based it on the principle of national sovereignty.
The Cortes were responsible for the Constitution of 1812, published on 19 March and colloquially known as La Pepa.
This constitution marked the end of the Old Regime in Spain and contained the basic principles of liberalism.
At the end of the War of Spanish Independence, Fernando VII returned to Spain.
With the support of the absolutists (shown through the Manifiesto de los Persas), he abolished the Constitution and the reforms of the Cortes de Cádiz and reestablished absolutism.
The repressiontowardsliberals, who led several pronunciamientos (military uprisings) against the absolutist regime of Fernando VII.
The War of the Spanish Independence started in 1808 and lasted until 1814.
The majority of the Spanish population considered Fernando VII as the legitimate king during the war, while a minority supported the new monarchy of José I.
The Spanish used guerrilla warfare and had the military support of Great Britain to weaken the French invaders.
Napoleon signed the Treaty of Valençay in 1813, recognizing Fernando VII as King of Spain.
The Cortes were summoned in Cádiz in 1810 to direct the war effort against the French and were responsible for the Constitution of 1812.
After the War of Spanish Independence, Fernando VII returned to Spain and abolished the Constitution and reforms of the Cortes de Cádiz.
Fernando VII's reign was marked by repression towards liberals, the independence of Spanish colonies in America, and the problem of succession.
The independence of Spanish colonies in America was led by criollos and inspired by Enlightenment ideas and the example of the USA.
The problem of succession led to the Primera Guerra Carlista (1833-1839) between supporters of Isabel and supporters of Don Carlos.