Mexico had declared its independence from Spain. With that being said, Spain had a war that lasted 11 years with them. After one town had declared independence, they started to spread as they had recruits coming in from everywhere. Finally, a Spanish soldier had joined in 1820 and brought an army to Mexico city, eventually capturing it.
One year later, Spain agreed to terms.