"Gandalf was a 5th-level magic user."
So stated a letter in The Dragon magazine (#5, March 1977). Given the low magic of the lands of Middle Earth, that may not be a bad approximation.
Not everyone agrees it's the best way, but it is certainly possible to play a campaign in Middle Earth using D&D rules. Attached here you'll find one way of doing it using the 3rd Edition d20 rules set. Full character stats for the characters of The Fellowship of the Ring are provided so you can launch your own adventures in Middle Earth.