Twain's purpose in The Adventures of Huckleberry Finn is to expose moral hypocrisy in "good" society, and he used attitudes in the South toward slavery before the Civil War as his touchstone. In order to effectively satirize the cruel social norms about slavery that passed as righteous and civilized in the Old South, Twain needed a naive character. That character is Huckleberry Finn, a marginal, untamed figure in his society who cannot quite learn how to behave or internalize the rules, but who nevertheless believes unquestioningly in the "morality" he has been taught.
By showing how innocently Huck believes he is a bad person and a sinner for protecting an escaping slave, the novel reveals the sick, upside-down morality of slavery and, by extension, any exploitation of one human by another. Of course, we as readers know that Huck is acting morally and courageously as he befriends Jim, even if Huck does not.
At a pivotal point in the novel, Huck assumes responsibility for himself and makes a moral decision that he believes will send him to hell. Nevertheless, he follows the dictates of his heart. In some of the most moving lines of the novel, we as readers learn the essence of true morality from this innocent, ostracized boy who is willing to sacrifice not only his body but, as he believes, his eternal soul to protect a person he loves:
But somehow I couldn't seem to strike no places to harden me against him, but only the other kind. I'd see him standing my watch on top of his'n, 'stead of calling me, so I could go on sleeping; and see him how glad he was when I come back out of the fog; and when I come to him again in the swamp, up there where the feud was; and such-like times; and would always call me honey, and pet me, and do everything he could think of for me, and how good he always was; and at last I struck the time I saved him by telling the men we had smallpox aboard, and he was so grateful, and said I was the best friend old Jim ever had in the world, and the only one he's got now; and then I happened to look around and see that paper.
It was a close place. I took it [a letter exposing Jim] up, and held it in my hand. I was a-trembling, because I'd got to decide, forever, betwixt two things, and I knowed it. I studied a minute, sort of holding my breath, and then says to myself:
“All right, then, I'll go to hell”—and tore it up.