By it's basic design from fantasy writings, D&D is basically a struggle between good and evil, law and chaos, and some neutral thrown in for good measure. By design the goal was to defeat the evil, unlawful ones . However, sometimes the bad guys win. I was thinking of the Elric series by Michael Moorcock. Elric was tormented and controlled by gods and forces beyound his control, namely Stormbringer. After 7 books and many adventures law and good prevail. ToEE is like that, in the end the demoness goes back to hell and law and good , once again, prevails. Evil can be very powerful, but in the end , they lose. I like it that way.
What I liked about Elric's world, and moreso Corum's, is that absolute Law was just as bad as absolute Chaos. Absolute Law meant a stagnant grey plain of boredom where no deviation from rules and discipline was allowed. The best case scenario was always Balance, not Good (really Law in Moorcock's stuff) as you've asserted.