Spanish attempts to reconquer Mexico
Mexican independence was officially achieved on September 27, 1821, under the Treaty of Córdoba. Spain did not recognize the treaties, arguing that the viceroy Juan O'Donojú had no authority to recognize the independence of any overseas province. This situation was dangerous to the newly acquired independent status of the nation, which had not yet been recognized by any of the European powers that could support it, and the threat of Spanish reconquest was a constant worry to the leaders of the nascent regime. On May 13, 1822 decrees were issued by the government to imprison anyone who conspired against Mexico's independence.
Mexican War of Independence
On 28 December 1836, Spain recognized the independence of Mexico under the Santa María–Calatrava Treaty, signed in Madrid by the Mexican Commissioner Miguel Santa María and the Spanish state minister José María Calatrava. Mexico was the first former colony whose independence was recognized by Spain; the second was Ecuador on 16 February 1840.