>>724679472
Gandalf is a Maiar (lower angel if you will) and in a sub category known as Istari (wizards). He was given mortal form and basically a lock on his power so that he would guide humans in the wars to come instead of directly intervening.
This agreement goes waaaaaay back to the days of Melkor (Sauron's master) when he was the big dog and ruining shit. The Valar (higher angels/lower gods) intervened and wrecked his ass, destroying continents in the process. Melkor knew he couldn't beat them outright, so instead he poured his power into his creations (dragons, orcs, trolls, etc.). By fighting "proxy wars," the Valar wouldn't directly intervene and instead assist humanity and guide them to fight back in fear of destroying part of the world again. Eventually the Valar said fuck it and did intervene, throwing Melkor's ass into the void, a permanent and inescapable prison where has has never been heard from since. Keep in mind, the reason they intervened was because he was a Valar as well, and thus pretty powerful. They didn't intervene for Sauron since he's below them.
It's also important to note that magic and the acts of creation are limited. Characters who use it, lose it, so to say. You have a limited pool to pull from that never refills, so Gandalf was pretty picky when it came to using his already limited power. Same thing with Sauron, that's why he forged the ring, because it could contain most of his power and never degrade/run out but could also be lost/stolen so there's that. Only Eru (the big GOD) has unlimited power because he has the Flame Imperishable.