The Influence of the French Revolution
Napoleon established his brother Joseph as Spanish king, but the resentful Spaniards fought a 5-year Independence War against the French. After Napoleon's definite defeat at Waterloo in 1815, Ferdinand VII was restored to the Spanish throne and reigned with a very rigid, absolute system of government.
The King changed the law of succession in such a way that his daughter Isabel was the next Queen. His brother Charles was against this and rebelled, leading to a dynastic falling out which ended up in civil war. This internal strife resulted in economic recession and political instability. Spain lost all its colonies with the exception of Puerto Rico, Cuba and the Phillipines.
In 1895 the Rebellion of Cuba resulted in a war against United States , with disastrous results for Spain. It put an end to what had been left of the Spanish colonial empires: Cuba, Puerto Rico and the Philippines were all turned over to the victors; Spain had now lost its last overseas possessions.