The Brazilian War of Independence (Portuguese: Guerra de Independência do Brasil) was an armed conflict that led to the separation of Brazil from the United Kingdom of Portugal, Brazil and the Algarves. The war was fought across various regions of Brazil, including Bahia, Maranhão, Pará, Piauí, and Cisplatina (present-day Uruguay), with naval battles occurring along the Atlantic coast. Brazilian forces, consisting of regular troops, local militias, and a hastily assembled fleet, defeated the Portuguese garrisons to establish the Empire of Brazil under emperor Pedro I. The war formally ended with the Treaty of Rio de Janeiro in 1825, in which Portugal recognized Brazil's independence.
After the outbreak of the Liberal Revolution in 1820, which forced king John VI to return to Portugal in 1821 after more than a decade in Rio de Janeiro, tensions between local Brazilian elites and the Portuguese Cortes arose. During his stay in Brazil, John VI had elevated the colony to the status of a kingdom in union with Portugal. The changes allowed Brazil to have its own government institutions and directly trade with the rest of the world, which many elites sought to preserve. Efforts by the Portuguese Cortes to restore Brazil to its former colonial status and reduce its political autonomy were met with resistance in various provinces. The tensions culminated in prince regent Pedro of Braganza's proclamation of independence on 7 September 1822, in what became known as the Cry of Ipiranga. Northern provinces, such as Bahia, Maranhão, and Pará, which maintained stronger ties with Portugal than the government in Rio de Janeiro, resisted Brazilian sovereignty, with Portuguese garrisons keeping control of key cities such as Salvador, São Luís, Belém, and Montevideo, in the South.