When Huck catches Tom in private, he asks Tom what his plan was if they had successfully escaped with Jim. Tom says he planned to have more adventures with Huck and Jim before revealing to Jim that he was free. After that, he would have compensated Jim for his lost time and reunited him with his family in style. Huck thinks it’s just as well that things turned out as they did.
It is small comfort that Tom recognizes he was denying Jim precious time with his family as a free man, but that does not change the fact that Tom exploited Jim. Huck recognizes all of this, and that they are better off having cut the games short so that Jim can enjoy his true freedom with dignity.
Jim is unchained, and the Phelpses and Aunt Polly, upon learning how Jim helped Tom, take very good care of the newly freed man. Tom also gives Jim forty dollars for being such a patient prisoner, such that Jim can remind Huck that he predicted he would be rich, and now he is.
Jim’s rewards for helping Tom seem paltry in comparison to the time he lost and the hardships he suffered. Jim, however, rejoices, maybe because it is in his character to make the best out of a bad situation, or maybe because Twain’s representation of Jim here is in some ways racist and dehumanizing. (There are many critics by the way, who would argue that the novel is fantastic up until the appearance of Tom Sawyer, and who argue that Twain didn't really know how to end the novel and ended up reintroducing Tom and focusing more on the broad comedy of the escape, and mocking Tom's romantic ideas, than with his earlier focus on Huck's development and poking holes in the institution of slavery).
Tom suggests that he and Huck and Jim travel to the Territory for adventure, but Huck says he doesn’t have enough money. Tom says that Huck still has six thousand dollars in Judge Thatcher’s care, because Pap didn’t take it and hasn’t even been in town. Jim explains that Pap died; his was the corpse that Jim discovered in the floating house.
Just as Jim is freed, so too is Huck with the knowledge that he has enough money to get away from society and do what he wants in the Territory, which, note, as a region not yet transformed into states has fewer rules, including rules of slavery. He also learns that he is once and for all free of Pap’s tyranny, because Pap, through his own debauchery, has passed away.
Eventually, Tom heals completely. Huck is glad he doesn’t have anything more to write about, because, he says, making a book was hard work. He says that he needs to head out to the Territory soon; Aunt Sally is going to try to “sivilize” him, which he can’t stand, because, he says, “I been there before.”
Huck ends his book where he began: with the prospect of being “sivilized.” But, being the restless and freedom-loving spirit he is, Huck refuses to do what he’s already done, and so he decides to pursue freedom in a place he hasn’t been yet, a place that is itself half-formed and semi-lawless, a place where a quick-witted boy can adapt to situations as needed and follow his own heart.