Karmic Twist Ending

Imagine, if you will, that a character does something despicable or foolish. Perhaps they were acting in an immoral way; perhaps they merely dared to rally against fate / the gods / the futility of existence / their own humanity. Whatever the reason, the universal kismet doesn't like it, so something totally unexpected but poetically just happens at the end to drive the lesson home, hard. Such endings are all but explicitly moralistic; it isn't enough for the universe to bring a situation to a just resolution, it has to resolve the situation in such a way as to both reveal what the moral of the story is and "demonstrate" the correctness of that lesson. This is a Karmic Twist Ending -- a Twist Ending designed to force An Aesop.

Much of the power of this trope derives from the twist at the end; it isn't merely unexpected, but it suddenly puts established plot elements into an entirely new light, revealing them to be loaded with new meaning via the connection to the aesop. Sometimes these connections are causal or logical, and sometimes they're merely metaphorical. Such a sudden shift of meaning is essential to the trope.

For example, a Corrupt Corporate Executive makes a huge deal via unethical tactics... But it turns out that the deal was with the devil, and he's just lost his soul.

A guy comes across a device that stops time and uses it to make himself rich, spy on the girls' locker room, etc... But it breaks, stranding him in stopped-time.

A diminutive cheating jockey wishes he wasn't so short, and his wish is granted... Turning him into a 10-foot tall freak who can't ride horses any more.

Whatever the case, the ending always makes the lesson to be learned abundantly clear in the end.

It's worth noting that when many people claim that a situation is an instance of 'Irony', they mean that this trope seems to apply to it. Often this usage is applied to actual situations, and denoting this trope with 'Irony' is one of the most familiar ways to apply the comfortable sense of narrative closure found in fiction to real life. Some who are supposed to know about this sort of thing think that this is an incorrect usage of the term, and the rest are familiar with the term "situational irony".

Compare to Earth All Along, Tomato Surprise, Fawlty Towers Plot, and Cruel Twist Ending.

As this is an Ending Trope, beware of spoilers.

Anime and Manga

 * Hell Girl is fond of Twist tropes, here are a few. In this show, if you send someone to hell, you will go to hell when you die.
 * An episode where a girl becomes extremely bitter at her teacher.
 * A girl becomes known for doing wiccan type stuff, which eventually leads to people asking her to put curses on other people.

Comicbooks

 * In the 70's, DC had a short lived comic called Plop!, in which a crew of ghoulish looking folks present stories, all of which end have that kind of ending. For example, a kindly old man is actually a secret grave robber who visits funerals only to inventory the jewelry of the deceased. But when the doctor tells him his time is coming, he's frantic to avoid the same treatment at the hands of his apprentice. So he stipulates that he be buried only in everyday clothes. Alas, he forgot that a dentist who believed the man's public image, had given him a free overhaul. And in the last scene, the apprentice is happily bashing out the gold teeth from the old man's corpse. After each story, the presenters cackle over the misfortunes of the characters before going on to the next story. Naturally, at the end of each issue, something goes "Plop!" on the presenters as well.
 * This particular variant (hideous narrators and all) was a staple of pre-Comics Code Authority horror comics, particularly those published by EC.
 * Later comic series like House of Mystery did these out of nostalgia for the old EC horror lines like Tales From the Crypt and its sister titles, The Vault of Horror, The Haunt of Fear, and Shock Suspenstories.

Films -- Live-Action

 * The 1968 film Wild in the Streets has an ending that could be considered an example of this.
 * Sid in Toy Story could count. He spends all his spare time sadistically destroying toys.
 * Judging by the Word of God about his cameo in the third game, he eventually got over it.
 * Doubly subverted in Kind Hearts and Coronets. The story revolves around a man who attempts to become the Duke of Chalfont by murdering everyone in line to inherit the dukedom.

Literature

 * The short story "Those Three Wishes", by Judith Gorog, is a literal case of Be Careful What You Wish For.
 * Roald Dahl's The Wonderful Story of Henry Sugar digresses to suggest "what a competent writer of fiction would have done" for the sake of a Twist Ending: to give Henry, who used his powers of X-Ray Vision for personal gain, some inventive manner of Karmic Death. In this suggested ending, Henry, feeling a pain in his chest, uses his X-Ray Vision to see all his internal organs and a blood clot slowly moving towards his heart. But Henry's story is not fiction (or so Dahl claims), so it must continue to the actual, not-so-dramatic ending.
 * In fact, this kind of twist occurs in many if not most of Dahl's short stories.
 * Stephen King's Thinner is also a pretty good example, if tending toward a Cruel Twist Ending. Rather than a Monkey's Paw wish, the story revolves around a curse brought on largely by the main character's irresponsibility. In the end
 * "The Necklace" by Guy De Maupassant contains one of the best known examples in literature.
 * Another classical example is The Queen of Spades by Alexander Pushkin.

Live-Action TV

 * Made famous by The Twilight Zone (former Trope Namer), though, ironically, it's the episodes that avert this trope that tend to be remembered best (such as "Time Enough At Last" which is a Cruel Twist Ending).
 * Completely and utterly averted in one of its most famous stories: "It's a Good Life", about a boy named Anthony with godlike powers. Arguably not as much, however, in "It's Still a Good Life", the sequel to the story in the 2002 series. Anthony has grown up and has a daughter named Audrey. She also has powers, but she can also bring things back from "the cornfield." The remaining townspeople (including Anthony's mother) try to turn her against her father, but it backfires and she banishes them all from existence. Anthony winds up saddened by this development, so she brings everything back. The two plan a trip to New York City, as Anthony states Audrey did a "real good thing" - acknowledging he is less powerful than she is and had better think happy thoughts himself. The closing narration reveals that there was no moral. "Just an update from Peaksville, Ohio."
 * In "Escape Clause," a man granted immortality in a Faustian Bargain, having accidentally killed his wife, casts it as a premeditated murder to see what the electric chair will do to him; his lawyer gets him a life sentence instead, and he calls on the Devil to collect rather than face centuries in prison.
 * In "I Shot an Arrow into the Air" the crew of a spaceship crashes on a hot, barren landscape with little hope of being rescued. One of the crew members, seeing that their water supplies are running low, kills the other surviving crew members to take their water. Then he finds out they weren't on a foreign world like they thought, but were actually in the Nevada desert, just a few miles from the road, and he breaks down upon realizing how pointless his actions were. The closing narration even refers to this twist as "A practical joke perpetrated by Mother Nature and a combination of improbable events, practical joke wearing the trappings of a nightmare of terror, of desperation."
 * Early B&W Lost in Space episode. Creepy skeletal starship wreck contains a device which will grant all wishes. No-one seems to notice the surviving bulkhead and door in the back of the wreck. Too many wishes (or irresponsibility) result in the door slowly opening...
 * The Revival version of The Outer Limits did this fairly often.
 * In "New Lease", two scientists invent a device that can revive the dead. They test it on various cryogenically frozen animals, then a person, but they find that every test subject can only last a day before it dies again. When one of the scientists is killed by a mugger, his partner decides to bring him back so they can have one last day together. The revived scientist, unable to let go of his desire for revenge and feeling he has nothing to lose, wastes the day tracking down the mugger, ignoring his friend and his family. When he finds the mugger, he murders him in public. To his horror, he finds out that the problem all along was the cryogenic freezing; having been revived as a fresh corpse, he's going to get to live to be arrested for the murder and most likely sentenced to life in prison.
 * If they just use the device on the mugger, he can at least have the lesser sentence of Aggravated Assault, if he's not forgiven entirely for inventing a machine that can be used to do exactly that.
 * And, considering the effects of the device on the human mind are undiscovered, he might even be able to get off on an insanity plea.
 * "Decompression" has a recently-elected senator aboard a plane that's going to crash. A time traveler tells him that he has to open the door and leap out, sacrificing the lives of all on board, so he can live to be elected President and usher in a new enlightenment, or else his opponent would be elected and become a ruthless tyrant. In the end, he jumps out with seconds to spare... whereupon the time traveler tells him that he was destined to become the tyrant, and lets him fall to his death while the plane lands safely.
 * "Skin Deep" has a nerdy guy gain a device that lets him change his appearance. He murders a handsome coworker and steals his identity, reveling in his new popularity and hot girlfriend and letting it all go to his head. Some mob enforcers whom the handsome coworker apparently had dealings with and cheated murder him.
 * "Second Thoughts" has a guy regularly murder people and use a device to absorb their memories and intelligence. He is greedy for knowledge. He makes the mistake of absorbing the mind of a suicidal artist, which causes him to go crazy and shoot himself in the head.
 * "Bits of Love" has a nuclear war survivor living in a bunker with holograms for companionship. Even through the holograms think and feel emotion like real people, he treats them with incredible disrespect, saying things like that they are not real so their opinions don't matter. In the end, the holograms reprogram themselves to completely ignore him and create a holographic society for themselves. The man lasts about a minute before he cracks from loneliness.
 * "To Tell The Truth" has a discredited scientist discover that his newly-founded colony is about to be wiped out by a solar flare. Given that his discrediting was due to a prediction of volcanic activity that caused the colony to be moved at great expense but failed to occur, no one believes him except his assistant and his mentor. He keeps on raising a fuss, until the colony's security chief reveals that evidence was found of an indigenous alien race when the colony was set up on the most valuable land on the planet - and not only accuses the scientist of being a shapeshifting saboteur trying to break up the colony, but condemns him with a DNA test that shows bizarre readings. He is then imprisoned and threatened with dissection, but the assistant, holding one last ounce of trust in her mentor, meets him in secret and tests him again to reveal that he is in fact human. As time is running out, the scientist, mentor and assistant attempt to escape the planet in the single emergency shuttle - and the scientist is mauled to death by a crazed mob while ensuring the escape of his two supporters. Afterward, the security chief mourns the scientist, and is mocked by the colony administrator for caring about an alien. The chief then reveals that he is the alien saboteur - he used his own DNA to fake the test - and states that it's ironic that the scientist, the only human in the colony he wished he could have spared for being "the gentlest of you", was the first to die, and at the hands of other humans - and then the solar flare hits, wiping out the colony and triggering the rebirth of the alien civilization.
 * "Family Values" has Tom Arnold play the workaholic, neglectful dad. He's annoyed by all the stuff his family wants him to do that keeps piling up while he spends nights and weekends with his boss and clients, so after being (deservedly) relegated to the couch by his wife, he sees an infomercial for a servant robot called the 'Gideon 4000.' He orders one for no money down. Initially, his family is creeped out, but the robot looks out for them and they grow to like it. However, after Tom Arnold sees the thing teaching his son how to play baseball, he sees it as moving in on his family. He can't return it without his wife's signature, which she won't grant. After an unsuccessful attempt to destroy it, the robot points out that he's become nothing but a money faucet because of his neglectfulness and that he's easily disposed of. The episode ends with the dad meekly apologizing to Gideon for forgetting to wear a tie to dinner and a montage shot of several families sitting down to dinner with their Gideon robots.
 * In the Tales From the Crypt episode "Top Billing," a struggling actor played by John Lovitz competes with his more handsome and successful former rival for a role in a production of Hamlet. When his rival is chosen for the role based purely on his looks, Lovitz's character murders him, and in his absence is accepted to fill in his role... which is revealed to be the role of Yorick.

Music

 * The lyrics in Ozzy Osbourne's Trapdoor (from his 2010 album Scream) seem to talk about someone that fell victim to his own hubris (and the Nemesis that comes with it).

Newspaper Comics

 * Spoofed in a Bloom County story arc. Oliver invents a device that turns people black (as in, of African descent) and tests it on an unwitting Steve Dallas. A couple of strips later, Steve finally noticed and, when talking to Binkley, theorizes that it's a Twilight Zone-style event where he was turned black in return for his occasional racism. The strip ends with Steve searching the bushes for Rod Serling.

Western Animation
"Finally! Solitude! I can read books for all eternity! (glasses fall off) It's not fair! IT'S NOT... Oh, well, my eyes aren't that bad. I can still read the large print books. (eyes fall out) IT'S NOT... Oh, well, lucky I know Braille. (hands fall off, screams, tongue falls out, head falls off) Hey, look at that weird mirror!
 * This trope was more than once parodied on Futurama's The Scary Door:

Bender: Cursed by his own hubris."

"Mad Scientist: I have combined the DNA of the world's most evil animals to make the most evil creature of them all!
 * A second Scary Door segment piles on one nonsensical twist after another (most of which based on real Twilight Zone episodes); a professional gambler is hit by a car and wakes up in front of a slot machine. He keeps on winning and believes himself to be in heaven, but when he realises winning all the time is boring, he realises he is in hell... Until a man arrives, pulls back a curtain and reveals he is in fact on an airplane. The gambler notices a gremlin on the wing and tries to tell the man, who simply replies "Why should I believe you? You're Hitler!" and holds up a mirror to reveal that the gambler has transformed into Hitler. He then begs Eva Braun, who is sitting next to him for help, but she pulls off a mask to reveal she has the head of a fly. Cutting back to the characters watching the TV show, Bender nonchalantly says "Saw it coming."
 * And in another:

Creature:"

"Narrator: In the end, it wasn't guns or bombs that defeated the aliens, but that humblest of God's creatures... the Tyrannosaurus Rex."
 * Then there's this parody:

"Scientist: If only I'd ordered the robot to make me be more careful with what I wished for! Robot, experience this crushing irony for me.
 * A more recent episode had a Brilliant but Lazy scientist invent a robot to do all his work and fulfill his social obligations. When the robot starts winning Nobel Prizes and the love of the scientist's family:

Robot (falling to knees): NOOOOOOOOO!!

(The scientist sips a beer and sighs contentedly.)"


 * In the "Wasted Talent" episode of Family Guy where Peter had to get drunk to play the piano, the final scene shows his solitary bookworm brain cell in despair after breaking his glasses, alluding to the Twilight Zone episode "Time Enough at Last."
 * The Simpsons took a twist on the Twilight Zone episode “A Kind of a Stopwatch” in "Treehouse of Horror XIV." Bart and Milhouse find a stop watch that stops time, make mischief, and break the watch. Unlike the Twilight Zone episode, they find a watch repair book and take 15 years to fix it.

Video Game

 * Mass Effect 3 pulled a pretty sharp twist at the ending: At the end it is explained that the Reapers only kill all organic life out of paranoia that they will create all-powerful A Is that turn against organic life. The only way to rid the Galaxy of the genocidal Reapers is not only for Shepard but also to choose one of three fates for the Galaxy, each imparting its own type of Aesop at the end.
 * Not really an aesop since its possible for the galaxy to already learn the aesop without being blasted to pre FTL