Huck is beset by a troubled conscience from early on in the novel. When he sees his friends and the widow searching for his dead body, Huck finds himself in a lonesome place. Soon, however, he meets Jim and his real dilemma begins.
Jim makes Huck promise not to turn him in to the authorities and Huck agrees. In this moment, Huck realizes that he is siding with Jim against society and the laws of that society.
People would call me a low-down Abolitionist and despise me for keeping mum—but that don't make no difference.
The way that his culture works in him, Huck believes that crime is equivalent to sin. This leads to a deep conflict in Huck as he attempts to justify helping Jim escape to freedom throughout the novel. In all his efforts, he cannot shake the sense that his actions will condemn him and that helping Jim, a good friend and a nice man, is a sin.
Huck folds to this crisis on one occasion, but changes his mind at the last minute. He leaves Jim on the raft with the intention of turning him in, then covers for him when questioned by two men on the river. Here, as later, Huck is faced with what he sees as two paths - act morally according to society or act morally according to his own sense of right and wrong.
As always, Huck chooses to do what he feels is right. His native sense of morality works more strongly in him, despite the fact that he cannot disbelieve in society's moral authority.
Ultimately, Huck decides to abandon at least the agonies of conscience because he cannot abandon this sense that society is invested with true moral authority. He cannot agree with the morality of certain laws, and so he cannot follow them. He also cannot escape his sense of the religious potency of these laws.
The decision to help Jim escape from the Phelps represents Huck's final acquiescence to the idea that conscience will harass a person no matter what he does. One must therefore think for oneself and act. This is his conclusion.
The situation that describes the last iteration of Huck's dilemma is ironic for two reasons. First, Jim is already free. Huck need not agonize about helping him escape. His crisis is real for him, but false in a circumstantial sense.
Second, from today's perspective, the institution of slavery is immoral. Helping someone to escape from an immoral imposition is definitively moral.