By the late 1700s, the Spanish colonies had a thriving class of Creoles: men and women who were born in the colonies but had European ancestors. By the late 18th century, Spain appointed mostly native-born Spaniards to important positions in the colonial administration.
The colonies were only allowed to trade with Spain, so, many took to selling their goods illegally to British and American merchants.
No free trade
The American Revolution was seen by many in South America as a good example of colonies throwing off European rule.
Americans, not Spaniards
There was a growing sense in the colonies of being different from Spain. The locals preferred to be called Americans and not Spaniards.
Napoleon invades Spain
The most important factor is probably Napoleon's invasion of Spain. It pushed many undecided Creoles over the edge in favor of independence.
By the time Spain was beginning to stabilize, colonies in Mexico, Argentina, and northern South America were in revolt.