I wouldn't say Gollum is one of my favourite characters, but he's certainly one of the most interesting.
He comes across as a useless nasty little sh*t but wise Gandalf suspects early on that he might be involved in the grand scheme of things-
"Even Gollum may have something yet to do".
That prophecy comes true at the end because
it's Gollum who inadvertently saves Middle Earth, NOT Frodo..
1- After climbing Mount Doom to destroy the One Ring by throwing it into the volcano, Frodo at last succumbs to its power and can't do it, and puts the ring on his finger..
2- Gollum bites off Frodo's finger with the ring on it..
3/4- They grapple on the edge of the crater..
5- And Gollum loses his footing and topples backwards into the molten lava, killing himself and destroying the ring..
Later, Frodo admits-
"But for him, Sam, I could not have destroyed the Ring. The Quest would have been in vain, even at the bitter end. So let us forgive him! For the Quest is achieved, and now all is over...'"