When Huck's moral conflict (a driving force in the novel) reaches its climax, it is Jim's good nature and steady friendship that sways Huck to his decision.
Earlier in the novel, Huck plays tricks on Jim and has fun at Jim's expense until Jim expresses a fully articulated and emotional response to Huck's behavior.
En when I wake up en fine you back ag'in, all safe en soun', de tears come, en I could 'a' got down on my knees en kiss' yo' foot, I's so thankful. En all you wuz thinkin' 'bout wuz how you could make a fool uv ole Jim wid a lie.
This is Jim's longest speech in the text and it is the one that brings Huck to see Jim's sensitivity and his humanity along with his good nature. While Jim was worried about Huck's safety and glad to see his return, Huck was playing a mean-spirited trick.
Later, Huck saves Jim from two slave-hunters through a lie about small-pox. Jim's response to this episode is to claim that Huck is Jim's only friend; the only white man who ever kept a promise to him.
When Huck sits deliberating about his course of action after Jim has been sold by the Duke and the King, these words return to Huck. Considering two courses of action, to write a letter to Miss Watson and abandon Jim or to find a way to free Jim from captivity, Huck reflects on his friendship with Jim.
...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...
These thoughts on Jim's good nature persuade Huck to save Jim, putting himself at risk.
The decision Huck makes at this point is a definitively moral one. As he contemplates Jim's good nature, Huck is deliberating on which is the right path, morally. Freeing Jim will be against the law, and immoral in Huck's view, but abandoning Jim would be immoral as well.
Huck even believes that he will be damned for breaking the law to help Jim escape, yet he cannot ignore or overcome the notion that Jim is his friend - and a good one - deserving of his help. The salient point in Huck's deliberations really is the care and friendship that Jim showed to Huck throughout their journey together.
Betraying Jim would be tantamount to betraying the values of friendship. This, ultimately, is an immoral act in Huck's view.