Columbus was working for Spain when he "discovered" the Americas. By keeping detailed records and maps, he and subsequent explorers were able to stake claims to various islands and lands for the Spanish monarchs.
Later, the Catholic Church brokered a deal between Portugal and Spain: All lands WEST of a certain longitude went to Spain (mostly Central/South America, everything EAST (esp Africa and Far East) went to Portugal. Brazil was a strange case, because the coastal zones (first places colonized) were east of the line. Since the Amazon was uncharted and went DEEP into the Continent, Portugal got most of the Amazon basin.