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, he abolished the Constitution and the reforms of the Cortes de Cádiz and reestablished absolutism.
The repression towards liberals, who led several pronunciamientos (military uprisings) against the absolutist regime of Fernando VII.
The independence of the Spanish colonies in America (1816-1825), with the exception of Cuba and Puerto Rico
This process was led by the criollos, the Spanish people who were born in America and lacked political rights.
It was inspired by the ideas of the Enlightenment, the example of the USA, the power vacuum caused by the French occupation of the Iberian Peninsula
Relevant generals of the American independence were San Martín and Simón Bolívar
To guarantee the succession of his daughter Isabel, Fernando VII abolished the Ley Sálica through the Pragmática Sanción.
The Ley Sálica prevented women from inheriting the crown if there was a male heir available, which in this case was the Infante Carlos María Isidro, brother of Fernando VII.
María Cristina, the mother of Isabel, looked for support between the liberals (isabelinos), while the the absolutists supported the succession of Don Carlos (carlistas)
During the reign of Isabel II, the liberal State was constructed and consolidated, being conservative in character but organised in two political parties: the Moderados and the Progresistas.
The principles of liberalism were shared by both parties but they disagreed on matters such as the role of the crown in politics, the Church, the suffrage, and the economy.
The monarchy of Isabel II was marked by the confrontation between the two liberal ideologies, the intervention of the crown and the Army in political affairs, and the marginalisation of most of the population from politics.
Pronunciamientos against political rivals were constant and the queen showed favouritism for the members of the Partido Moderado.
The reign of Isabel II became very unstable and ended in the Revolución Gloriosa against the Crown in 1868.
Her reign is divided in two main stages: the regencies of María Cristina and Espartero, and the direct reign of Isabel II.
During the regencies of María Cristina and Espartero, the Primera Guerra Carlista developed, ending in favour of the isabelinos in 1839 through the Convenio de Vergara.
The Constitution of 1837, of progressive ideology, was also approved during this period, as well as the desamortización of ecclesiastical lands of Mendizábal.
The disputes between liberals forced both regents to resign, and in order to avoid a new regency, the Cortes proclaimed Isabel II of age when she was 13 years old.
During the direct reign of Isabel II, the liberal regime was consolidated and reforms were applied to try to modernise the country, with mixed results.
The Moderados were in power most of the time with the support of the queen, and they passed a new moderate Constitution and the Reforma fiscal of Mon and Santillán in 1845, a Concordato con la Santa Sede was signed in 1851, and the Guardia Civil was created in 1844.
The Progresistas were able to hold power for some time, and they passed the Ley General de Desamortización of Madoz and Ley General de Ferrocarriles in 1855, as well as some bank laws, and redacted a new progressive Constitution in 1856 (it was never approved).
Despite the triumph of liberalism, the political discontent among Progresistas and other political forces, like democrats, led to the Pacto de Ostende in 1866 to end the monarchy of Isabel II.
In 1868, the signers of the Pacto de Ostende led the Revolución Gloriosa that forced the queen into exile.
The six-year democratic period (1868-1874) was marked by the attempt to democratise the liberal regime in Spain and to exile the Borbones, considered the cause of the problems of the nation.