At the end of 1810, Ferdinand VII of Spain, captive, was recognized by the courts of Cadiz and by the governing juntas in the Americas as a subordinate king to popular sovereignty. In agreement on this, a military conflict arose between Royalists and Patriots over the unity or independence of the empire. However, in 1814, with the defeat of Napoleon after the treaty of Valençay, Ferdinand VII returned, and with a coup d'état, reimposed absolutism. Ferdinand was able to defeat and repress the peninsular liberals, and abolished the republican Constitution of Cadiz, although he could not defeat the revolutionaries, who resisted and formed their own national congresses. The Spanish navy had collapsed in the war against Napoleon, so therefore, in practice, was supporting the expeditionary forces who arrived in small groups. In 1820 the Spanish army, led by Rafael Riego, revolted against absolutism, restored the so-called Trienio Liberal, and ended the threat of invasion against the Río de la Plata and Venezuela, but did not change the position of Spain against separatism, resulting in the defenders of the King collapsing in Americas. Over the course of the next decade, the Patriots’ armies won major victories and obtained independence in their respective countries. The political instability in Spain, without a navy, army or treasury, convinced many Spanish Americans of the need to formally establish independence from the mother country. In Spain, a French army of the Holy Alliance invaded and supported the absolutists, restored Ferdinand VII, and occupied Spain until 1828.