There were five of them. Not gods, not elves, not men. They came to Middle Earth early in the Third Age.
Forming the Order of Istari, the wizards were sent by the Valar to help the elves and men in their efforts against evil Sauron. Though Tolkien never described their nature, they may have been lesser Valar–embodied angels. In any event, they arrived in Middle Earth early in the second millenium of the Third Age in the form of old men. Two of them went East and no one knows what happened to them; one became enamored with the forests and animals and gave no care to the issues of men and elves; one of them, the leader of the group, became corrupt and worked against elves and men. The last, Gandalf, stayed faithful to his role and played a crucial role in the defeat of Sauron.
Gandalf was the last wizard to arrive on Middle Earth, last in arrival and last in appearance. In the words of Tolkien in an unfinished tale, “last came one who seemed the least, less tall than the others, and in looks more aged, grey-haired and grey-clad, and leaning on a staff.” He slowly walked all over Middle Earth with the help of a cane, quietly urging elves and men to do good and advising them on the best course to take in the constant battle against Sauron, whose shadow was infiltrating almost every area of Middle Earth. He never seemed to have a grand plan, like a social planner working to mold and control society in conformance with his ideas. He merely worked in the pockets of goodness he found.
He found goodness in the lesser race of the dwarves, so he encouraged their king, Thorin Oakenshield, to undertake a seemingly-suicide mission with eleven companions against the evil dragon Smaug of the Loney Mountain. As a result of the mission, a thriving community of goodness formed around the formerly-disjointed region of the Lonely Mountain, a community that was able to halt Sauron's forces that hoped to ravage the northlands as all the powers of goodness were concentrated in the South at the end of the Third Age.
He found goodness in the Shire, so he solicited Bilbo Baggins to accompany Thorin's mission, with the result that Bilbo found the One Ring, the destruction of which would end Sauron's power forever.
He found goodness in the treepeople, called Ents, so he urged them to battle back against their oppressor, Saruman, with the result that Isengard was devastated by these root-strong huge creatures, and a potentially-formidable force was eliminated before it could help Sauron.
Gandalf was the man working behind the scenes. He didn't seek his self-glory; he merely sought to do good, in obedience to his masters who sent him to Middle Earth. He was humble but wise, so he was eventually cast into the limelight as an unparalled leader when things became darkest and the efforts of men and elves were wavering, but he never sought the limelight. By the time he left Middle Earth, he had well-illustrated Christ's words that the least shall become the greatest: Through perfectly selfless service in the name of goodness, he became the greatest of creatures on Middle Earth, but then he left, knowing his mission was accomplished, staying only long enough to hug those he helped then leaving them to enjoy the fruits of his labor.
Gandalf is Tolkien's Middle Earth saint: humble but wise, strong but merciful, joyful but discerning. He is the embodiment of a saint that refuses to disentangle himself from the affairs of the world and struggles with troubles just like lesser men. In Tolkien's unfinished tale about the Istari: “Warm and eager was his spirit . . . for he was the Enemy of Sauron, opposing the fire that devours and wastes with the fire that kindles and succours in wanhope and distress; but his joy, and his swift wrath, were veiled in garments of grey as ash, so that only those that knew him well glimpsed the flame that was within. Merry he could be, and kindly to the young and simple, and yet quick at times to sharp speech and the rebuking of follow; but he was not proud, and sought neither power nor praise, and thus far and wide he was beloved among all those that were not themselves proud.”