****************SPOILER ALERT*************************
I can think of three works
where the protagonist
was on the brink of death,
the narrative demanded he die
and
an editor or producer or redactor
tacked on a happy ending:
Terry Gilliam's Brazil,
Blade Runner and
possibly, the Gospel of Mark.