As you rightly pointed out, the manner in which the jerk dies (or more broadly, the manner in which his story ends) isn’t important in determining whether the audience gives up on him or not. They will long have made up their minds by then. In fact, if you don’t set things up right, then the more significant your character’s final gesture, the more annoying your character becomes after the fact (on top of how annoying he already was). Because it will all feel incredibly artificial.
So for me, the example that immediately comes to mind is Gollum (spoiler alert, I guess, if you’ve never watched/read The Lord of the Rings). He is precisely the sort of character that is up to no good for the entire length of the story, and is loathed by cast and audience alike. Sam wants to leave him behind, and Frodo even suggests killing him (in the movie, at least). Yet Gollum carries on as part of the narrative specifically so that he can perform the (figurative) ultimate sacrifice and save the world at the end.
There are several ways in which this is achieved. The first is that the protagonists need him. He’s their guide into Mordor. Without him, they’d be screwed.
Next is the fact that Frodo progressively identifies with Gollum—he recognizes what may be become of him should he give in to the power of the One Ring. Frodo needs to keep his hope alive that there is some sort of redemption at the end. So, through Frodo, we as the audience begin to empathize with Gollum, even if we still view him as an annoying bad guy.
Third, Gollum’s presence ratchets up the tension, not just between Frodo and Sam, but between the Frodo and the audience. He sows increasing doubt in our mind as to whether Frodo will ever complete his mission. And he does so while helping him through it.
In short, Gollum is a necessary actor who moves the plot forward, even if he does it as an anti-hero, or even as a quasi-antagonist. More than that, through this tug-of-war of helping/hindering the protagonist, he is the manifestation of the protagonist’s inner conflict, foreshadowing the failure lurking in the dying moments of the story.
But really that is the baseline for justifying the presence of any character in any story: what purpose do they serve? If they’re just here for the ride so they can perform a single action at the end, then they’re useless, and the reader will always wonder why they’re even here. If they’re crucial to the plot, then your job is to make it clear to the audience.
After that, the usual advice stands: your character needs to be interesting, and present a certain depth of character. Because a character who is nothing but a jerk is no more or less annoying than a perfect Goody Two-Shoes. Make him clever, making him funny, make him speak in rhymes, make him do unexpected things. Anything you add to elevate such a character from bystander to active participant will give the audience reason not give up on him.
TL;DR: Justify your jerk being an integral part of your story, and most importantly, make him interesting. Just as you would as any other character.