Portugal was similarly ruled by several governments: the military government first of France and then of Britain, whose troops either invaded or liberated (depending on whom was speaking) the country, a regency, and various juntas. The king in Rio de Janeiro also tried to control the Peninsula by issuing a series of orders to local officials, though his success in doing so was limited.In 1814, as the power of Napoleon was waning, the Spanish king, Fernando, returned to Spain, where he declared the Cádiz Constitution, and all that was enacted by the Cortes of Cádiz, void. A liberal uprising in 1820 forced the king to reinstall the constitution, but in 1823 it was again repealed. Meanwhile, the Portuguese Prince Regent remained in Brazil where, crowned as King João VI in 1815 after the death of his mother, he declared the formation of the United Kingdom of Portugal and Brazil. Under enormous pressure, probably linked to fears that Brazil would colonize Portugal, and after an uprising in Porto in 1820 that protested "the status of a colony to which Portugal in effect is reduced," the regency in Portugal agreed to call a meeting of a constituent Cortes. Threatened by these developments, João VI returned to Portugal in 1821, leaving his heir behind as regent. As he was departing, crowds in Rio de Janeiro forced him to swear allegiance to the Spanish Constitution of Cádiz, which they believed would ensure that the United Kingdom of Portugal and Brazil would become a constitutional monarchy that would protect equal relations between the Portuguese territories on both sides of the ocean. 7 The Portuguese Cortes, which met from 1820 to 1822, in 1822 adopted a new constitution for the United Kingdom of Portugal and Brazil. Yet, in response to these developments as well as pressures from locals, the heir to the throne, Dom Pedro, who remained in the Americas, declared Brazilian independence in 1822. He convoked a constituent assembly in 1823 but, ignoring most of its work, proceeded to impose a new constitution on Brazil in 1824. In Portugal, João VI began purging Portuguese liberal legislation of elements that according to him did not conform to the customs and will of the nation and, in 1824, declared the return to the Ancien régime, that is, all which existed before the imperial crisis.These European events greatly affected developments in Latin America. In Spanish territories, while some remained loyal to the captive king despite his deposition in 1808 and refused to adopt any measure that might amount to innovation, others formed local juntas, which, although swearing allegiance