Dividing the world was just a simple matter of a Papal agreement at the end of the 15th century:
After Columbus had returned from his first trip, the King of Spain asked the Vatican to rule over the division of the world between the two naval superpowers at the time, Spain and Portugal.
Portugal already had control of the eastern routes, so the Pope draw an imaginary line “370 leagues west of Cape Verde”, splitting the current Brazil in half. Everything west of that line would belong to Spain, and everything east of that line would belong to Portugal.
Easy as that.
This Treaty of Tordesillas took it for granted that whatever would be found, those lands and riches would belong to these two countries: never mind the locals they might find along the way.
All Vatican wanted in return was turning anyone they might find into faithful Christians.
The main reason for this treaty was the access to spices from Malacca, what is currently part of Indonesia: gloves, cinnamon, nutmeg and mace were more valuable than gold, and finding a fast and reliable route to these riches was worth some serious investment. As Portugal had control over the eastern route, Spain wanted to find out a westerly route to Malacca and back.
Thanks to the miscalculation made by Ptolemy and the maps based on his assumptions, the true size of the Earth was thought to be much smaller, and therefore, based on the distanced to Malacca as measured by the eastern routes, a western passage was seen as perfectly plausible alternative. Thus, wooing the kings and queens of the era to fund such an expedition was not very hard, as it potentially offered a way to vast riches, both for the funding royals and the crews participating in these voyages.
It's quite interesting to see how both Columbus and Magellan had both been driven more by ambition than nationality: Columbus was Italian but got his financing from Spain, and Magellan was ex-Portuguese soldier who leveraged the success of Columbus and managed to get a fleet of five ships and a crew of over 260 men funded by Spain, even though he had never been a captain before.
Magellan claimed to know of a passage that would allow crossing the South American continent: nobody knows whether this was a fact or just a way to get funding for an expedition, as finding anything valuable on these unchartered lands could still turn up to be worth the risk to all of the participants, and especially to Magellan. It is possible that he had heard references to what is the mouth of River Plata from someone who had sailed south from Rio de Janeiro: River Plata is wide and deep and could have been misinterpreted as a gateway across the continent. There are no known notes on why Magellan was so sure about the existence of such a passage, and the existing maps of the era did not go far enough South to include River Plata.
After leaving Rio de Janeiro Magellan spent three months investigating every possible inlet, including River Plata, and found nothing. The armada was now in the chilly and stormy waters of Southern Argentina, and the expedition was taking much longer than anticipated. Moral was low, and when Magellan reduced the daily rations for the crew, a mutiny ensued: the other captains demanded that they return back to Spain immediately. With a couple of loyal supporters Magellan managed to keep enough control to crush the mutiny, and the ringleaders were killed and chopped to pieces as a warning to others.
Majority of the crew ended up being pardoned, though, as Magellan still needed men to handle the ships, and his cruelty against mutineers had made it clear who was in charge.
The expedition went to the shore waiting for the Southern winter to pass, but when they continued sailing, things started going wrong again: first Magellan lost one of the ships in a storm and the captain of another ship, San Antonio, turned around without permission and slipped back to Spain.
The desertion of San Antonio was a big blow to Magellan, as that ship had most of the provisions for the whole fleet, but he was still determined to push forward. What gave him hope was the fact that the new inlet they had found had saltwater in it, indicating that it was not a mouth of a river but had some connection to ocean.
After navigating the twisty, 500 km long waterway through Tierra del Fuego for about a month, the three remaining ships finally came out to open sea again: they had finally reached the Pacific Ocean, which actually got its name right there and then by Magellan, simply because it appeared to be much calmer than the Southern Atlantic that they had left behind.
The connection between the Atlantic and the Pacific across what is now known as the Magellan Strait had been found, and it would become a major shipping route until the Panama Canal was opened in 1914.
After some further sailing Magellan was certain that they were only days away from Malacca, but his assumption was based on the estimate made by Ptolemy, and it was soon obvious that this figure was incorrect: it took them over three months to finally reach Guam, and by the time they reached the Philippines, only 150 of the original crew were still alive, many of them ill or suffering from scurvy.
Magellan was given a warm welcome by the local chief of the island of Cebu, Rajah Humabon, thanks in part to Enrique, a Malaccan slave who spoke the local language: Magellan had originally taken Enrique along for the trip exactly for the purpose of using him as an interpreter.
This was the high point of the voyage: they were near to their destination, back on the known sea routes, and now had access to good, healthy food again.
But the good times did not last—Humabon asked for Magellan's help to overthrow the ruler of a nearby island of Mactan, and he was happy to offer his help: after all, he could then convert yet another group into Christians, as had happened with Humabon's tribe. Unfortunately Magellan severely underestimated the enemy, ending up fighting a force of 1,500 men with a team of only 50: he was killed in the battle that ensued.
Enrique, who had been promised his freedom as a payment for the participation, saw his future prospects dim after Magellan's death: the remaining crew did not want to heed Magellan's promise of freedom, as they still had to reach the Spice Islands to make the trip worthwhile and having an interpreter would make the interactions easier. It is likely that Enrique used his language skills and conspired with the locals, causing an ambush that resulted in the death of about 30 sailors and setting him free. There are no more written notes of Enrique at this point, so he presumably jumped the ship and thus became the first ever person to circumnavigate the globe.
But the rest of the crew pushed on: as they did not have full crews for all three ships any more, they burned one of the ships and set sail with the two remaining ones to the Spice Islands, where they loaded the ships up to the hilt with spices.
One of the ships eventually sank after being captured by the Portuguese, but the last remaining ship, Victoria, finally made it back to Spain under the command of Juan Elcano, one of the mutineers pardoned by Magellan.
Out of the original crew of five ships and 260 sailors, only 18 made it back on board the last remaining ship. Naturally also the approximately 40-strong crew of San Antonio that had deserted Magellan just prior to crossing the Magellan Strait had survived. The captain of San Antonio had been jailed, but after the crew of Victoria described the multitude of hardships of the overall journey, the jailed captain was freed: his action was seen as being in the benefit of his crew.
Amazingly enough, the value of their spice cargo of just a single boat was enough to cover the whole cost of this expedition, even making some profit on top. But it was not for the benefit of the crew: the crown of Spain confiscated the cargo as a repayment for the loss of the rest of the fleet.
It had taken three years and formidable navigation skill to go around the world, and the man who got his name in history books ended up getting killed along the way, but his remaining crew had finally proven that there is a way to Spice Islands via the westerly route, it just happens to be very long and treacherous, and hence less worthwhile than was expected.
But for centuries the Magellan Strait was the only available passage for transferring large amounts of goods between the east and west coasts of the USA, as the Transcontinental Railroad was completed only in 1869.
Just like any navigators of today, Magellan and his crew were not using any “Flat Earth Navigation Rules” to finalize their circumnavigation: they knew the shape of the Earth, and that helped them to survive this arduous trip and find their way to the Spice Islands by using a route nobody had ever used before. The only error was Ptolemy's wrong estimate for the circumference of the Earth, which added 11,000 km of ocean crossing to their voyage
After all twists and turns, Victoria sailed a total of 60,000 km.
The final proof that the Earth is a a rotating globe came from the fact that the crew of Victoria realized that their meticulously kept daily log book was off by one day at the arrival back to Spain: they had circumnavigated the globe towards the west, opposite to the Earth's rotation and hence crossed the then non-existent International Date Line, losing one day in the process.
Before Magellan's expedition, the assumption that the Earth is a globe was accepted as a fact, but it was still just a theory: Magellan's expedition proved it in practice.
All this happened already 500 years ago, yet we still have people claiming that the Earth is flat.
Replica of Magellan's only surviving ship, Victoria.