The answer to this varies somewhat from country to country in South America. The general answer, though, is that the countries are independent because they fought revolutions to break away from Spain. Again, this is not true of all South American countries. Brazil, for instance, was a colony of Portugal and not of Spain. As another example, Suriname was a colony of the Netherlands. Unlike Brazil, it did not have to fight for its independence. It was granted independence peacefully in 1975.
But many South American countries became independent because they rebelled against Spain. This happened in the early 1800s. Spanish colonies fought against Spain because the Spaniards born in the colonies were tired of being treated as second class citizens by the Spaniards born in Spain.