The French invasion of Spain under Napoleon, also known as the Peninsular War, was in the duration from 1807 till 1814.
This invasion affected the Spanish colonies in the Americas as several colonies started to rebel in order to gain to gain their own independence from Spain.