For Portugal and Brazil, Napoleon's defeat did not immediately result in the return of the Portuguese monarch to Portugal, since Brazil was the richest part of the Portuguese empire. As with Spain in 1820, Portuguese liberals threatened power of the monarchy and compelled John VI to return in April 1821, leaving his son Pedro to rule Brazil as regent. In Brazil, Pedro contended with revolutionaries and insubordination by Portuguese troops, all of whom he subdued. The Portuguese government's threatened to revoke the political autonomy that Brazil had enjoyed since 1808, provoking widespread opposition in Brazil. Pedro declared Brazil's independence from Portugal on 7 September 1822 and became emperor. By March 1824 had defeated all armies loyal to Portugal. Brazil's independence was achieved relatively peaceably, territorial integrity was maintained, and its ruler was from the Royal House of Braganza, whose successors ruled Brazil until their overthrow in 1889.