I thought it had something to do with Spain getting everything west of a certain longitude and Portugal everything to the east, which is why the Spanish colonized Africa and spain the Western hemisphere; but they didn't figure that there was any land that straddled that line (i.e. Brazil)
Exactly. The Pope made the division along a longitudinal line, but the eastern tip of Brazil crosses it.