The land now called Brazil was claimed by Portugal in April 1500, on the arrival of the Portuguese fleet commanded by Pedro Álvares Cabral. The Portuguese encountered Indigenous nations divided into several tribes, most of whom shared the same Tupi-Guaraní language family, and shared and disputed the territory.
Though the first settlement was founded in 1532, colonization was effectively started in 1534 when King John III divided the territory into fifteen hereditary captaincies. This arrangement proved problematic, however, and in 1549 the king assigned a Governor-General to administer the entire colony. The Portuguese assimilated some of the native tribes while others slowly disappeared in long wars or by European diseases to which they had no immunity..
By the mid-16th century, sugar had become Brazil's most important export due to the increasing international demand for sugar. To profit from the situation, by 1700 over 963,000 African slaves had been brought across the Atlantic to work in Brazil. More Africans were brought to Brazil up until that date than to all the other places in the Americas combined.
Departure of the Portuguese royal family to Brazil on 29 November 1807.
Through wars against the French, the Portuguese slowly expanded their territory to the southeast, taking Rio de Janeiro in 1567, and to the northwest, taking São Luís in 1615. They sent military expeditions to the Amazon rainforest and conquered English and Dutch strongholds, founding villages and forts from 1669. In 1680 they reached the far south and founded Sacramento on the bank of the Rio de la Plata, in the Banda Oriental region (present-day Uruguay).
At the end of the 17th century, sugar exports started to decline but beginning in the 1690s, the discovery of gold by explorers in the region that would later be called Minas Gerais (General Mines) in current Mato Grosso, Goiás and the state of Minas Gerais, saved the colony from imminent collapse. From all over Brazil, as well as from Portugal, thousands of immigrants came to the mines.
The Spanish tried to prevent Portuguese expansion into the territory that belonged to them according to the 1494 Treaty of Tordesillas, and succeeded in conquering the Banda Oriental in 1777. However, this was in vain as the Treaty of San Ildefonso, signed in the same year, confirmed Portuguese sovereignty over all lands proceeding from its territorial expansion, thus creating most of the current Brazilian border.
During the invasion of Portugal (1807), the Portuguese royal family fled to Brazil, establishing Rio de Janeiro as the de facto capital of Portugal. This had the side effect of creating within Brazil many of the institutions required to exist as an independent state; most importantly, it freed Brazil to trade with other nations at will.
After Napoleon's army was finally defeated in 1815, in order to maintain the capital in Brazil and allay Brazilian fears of being returned to colonial status, King John VI of Portugal raised the de jure status of Brazil to an equal, integral part of a United Kingdom of Portugal, Brazil, and the Algarves, rather than a mere colony, a status which it enjoyed for the next seven years.