Gandalf was called Mithrandir in the The Lord of the Rings because he saved Frodo and the others from a fire attack by Ringwraiths.
“Mithrandir” is Quenya for “the Grey Pilgrim.” He did this by ferrying everyone to safety on his horse, Shadowfax. His wisdom helped keep Frodo safe all through his quest and led him to destroy Sauron in Mount Doom, too. Gandalf fought against Morgoth himself when he was still just called Olórin! There are stories passed down among elves and hobbits that say Mithrandir had indeed been about at important times before in ages past as well even when Tolkien’s tales were not yet written.