We've been saying throughout our Lord of the Rings learning guides that this series is about the confrontation between Good and Evil. But Frodo's struggles with the Ring on Mount Doom in The Return of the King present an interesting twist on the moral structure of Middle-earth. Frodo ultimately fails in his quest. But his intentions have remained pure throughout. And those intentions matter a great deal. In fact, they matter more than anything else. Thanks to Frodo's basic goodness, fate steps in and corrects Frodo's final failure. By contrast, Gollum is the one who actually destroys the Ring of Power. But he does so accidentally, so he dies unredeemed. Frodo does evil unintentionally, while trying to do good. Gollum does good unintentionally while trying to do evil. That makes all the difference in the world. Or at least in Middle-earth.
While much of The Return of the King focuses on the doubt and despair of good characters, the whole novel contains numerous hints that the good side will, eventually, defeat Sauron. Thus, the suspense of The Return of the King is not based on whether good will defeat evil, but how.
Gollum means to do evil but actually winds up accidentally doing good in Sammath Naur. The good he does cannot reflect positively on Gollum because he does not mean to do it. From Tolkien's perspective, it's clear that intentions matter more than actions.