Squatters is the answer given to this question in Brazilian history classes in school.
The last territory annexed by Brazil was the state of Acre, which was only legally settled in 1903, when Brazil agreed to pay Bolivia a sum of two million pounds sterling and build a railroad that would allow Bolivian produce to be transported up to the place where rivers started being navigable.
Short answer:
The Treaty of Tordesilhas divided South America but most of the land remained unoccupied. Before the slave trade from Africa, most of the workforce were enslaved indigenous. To collect these people were organized the Bandeiras, that would leave São Paulo to enter the unexplored interior. Some of these Bandeirantes were people like Fernão Dias and Raposo Tavares. The exploration led to occupation of the land and in 1750 Portugal and Spain signed the Treaty of Madrid based on the principle of Uti Possidetis where who occupied the land was it legitimate owner, defining most of the current borders of Brazil.