The 1494 Treaty of Tordesillas was an agreement between Spain and Portugal to divide the newly discovered lands of the rest of the world between them. Because Tordesillas only divided the Atlantic region, a second treaty, the 1529 Treaty of Zaragossa, divided the Pacific and Indian Oceans.
When Christopher Columbus returned to Spain after his discovery of the New World, he stopped at Lisbon and told the Portuguese King John II about his discoveries. Because the Portuguese had earlier been granted all land south of the Canary Islands by the Pope and in a Spanish treaty, John II argued that Columbus' new discoveries belonged to Portugal. Unfortunately for the Portuguese, a new Pope with Spanish ancestry, Alexander VI (also known as Rodrigo Borgia), had declared all lands west of the 38th meridian to be Spanish. This included nearly all of the Americas. Spain and Portugal ultimately compromised, pushing the meridian line westward to about 46 degrees. Shortly afterward, Portugal sent Pedro Alvares Cabral to the New World, where he discovered Brazil.
Later, Portugal's claim on the Moluccas inspired Spain to claim that the Tordesillas agreement was not just a line on the west side of the world but a full hemispherical division, which put the Moluccas on the Spanish side. The Pope adjudicated this disagreement as well, drawing the Zaragossa line to give Portugal the Moluccas and Spain anything east of that line.