In Sunrise, some of the characters are relaxing in the sun. Suddenly, Honeyfern is bitten by a venomous snake and has a seizure as she dies.
Then in Night Whispers, Flametail is playing on the ice when it cracks and he drowns.
In Dragon Bones, Ward has managed to lead all his people to safety, has his loved ones with him, and is reasonably happy while he watches the villains search his castle - he managed to avoid a lot of death and destruction. Then, he notices that his magically bound slave Oreg, who was strongly opposed to letting the villains take the castle, looks very happy too, which makes him suspicious. Correctly so, as Oreg asks Ward to kill him. He is bound to the castle, which after Oreg's death collapses. The villains can't get the eponymous dragon bones, and Oreg gets what he wants ... yes, he has wanted to die for a long time.
John Dies at the End is overflowing with this. Includes the main character, Dave, going from being beaten and nearly killed by a monster disguised as a policeman to talking to a dead friend using a bratwurst as a phone, a ghost trapping Dave and John in a house and then transforming itself into a meat monster "PREPARE TO MEAT YOUR DOOM!", and John making a snarky joke about "beastiology" to John watching a video of thousands of people including children being maimed by giant spiders and left to writhe.
In Harry Potter and the Philosopher's Stone, we have an adorable, Cinderella-like little boy exploring the wonderful world of magical, colorful wizards. Then, he sees his dead parents, he's almost killed by a mysterious blood-drinking figure, and he's confronted by a trusted teacher with the Big Bad growing out of his head.
Harry Potter and the Goblet of Fire, definitely. We have this awesome contest, with romance and rivalry, fun and games. and then we see two characters get shipped off to a graveyard, one killed for having tagged along in a ghastly manner, Harry tied to a gravestone, his blood taken from him, Voldemort coming back, him taunting him, ready to kill Harry, Cedric, and his parents coming back out of Voldy's wand, and a Death Eater impersonating as a teacher all year, who also tried to kill Harry.
The contest is always quite serious; there have previously been plenty of casualties in the regular tasks of the Triwizard Tournament before. It was originally discontinued because the death toll got too high.
Done both hilariously and heartbreakingly in Harry Potter and the Order of the Phoenix. Whilst on the ward for mentally damaged permanent residents of St Mungo's hospital, we see post-memory loss Gilderoy Lockheart, who is just as mind-numbingly stupid and arrogant as he was in Chamber of Secrets — and then straight afterward the absolutely devastating fate of Neville's parents is shown. Cut back to Lockheart talking about how he can do joined up handwriting.
In Deathly Hallows during the Battle of Hogwarts, there's an amusing scene when Percy defeats Pius Thickness ("Hello Minister, did I mention I'm resigning?"). Immediately afterwards, Fred gets killed.
The Baby-Sitters Club series — Claudia and the Terrible Truth, where the Very Special Episode-esque main plot (the girls finding out that two of their new charges are being abused by their father) is interspersed with the sitters helping kids preparing for a St. Patrick's Day parade.
The Hunger Games trilogy is loaded with these moments — they'll take you from heartwarming happiness, or seeing the characters laugh for the first time in weeks, directly to a horrific death and much despair.
Macbeth has a classic case. As Lady Macbeth goes off to kill the king, a scene that could be very disturbing to Elizabethan audiences, so Shakespeare followed it by a comic scene with the castle porter answering the door.
The last story of Brothers of the Snake starts with the trainees out-ambushing their teachers and everyone laughing at it, then takes a darker turn as it turns out that one of the trainees used the commotion to leave and attempt a trench dive, dying as a result.
The Kalevala is Finland's national epic, compiled in the mid-19th century from oral traditions that in turn date all over the previous centuries/millennia. At one point, it features the Eternal Sage, in search of words of power, descending into the Netherworld until he stands before its black river and meets the daughter of Death itself. She's short and fat, and washing clothes in Finnish!Styx. Yeah, that's right. At least to a modern audience, the prehistoric sagas subvert themselves when they start getting too serious.
Many of the short stories of Sholom Aleichem have a weird combination of humor and depressing reality. For example, in the short story Two Dead Men, we leave two of the main characters, one of which is so drunk he can't even remember the holiday it is, clumsily trying to get themselves out of the mud and look at his wife, who is worried her alcoholic husband's going to be found dead in a ditch.
The Discworld series is usually billed as 'uproariously hilarious' or the like, and in many places it is. However, there are many parts that range from dramatic and moving to outright horror—for instance, the torture rooms of the Particulars in Night Watch.
In Jingo, Vimes's plotline is juxtaposed with scenes of Vetinari, Colon, and Nobby in Al-Khali. What Vetinari is actually trying to achieve is in fact very serious (and is the same as what Vimes is trying to achieve, i.e. stopping the war) but because he has Colon and Nobby with him, the scenes are much funnier than Vimes's, who spends most of it wondering how he'll ever get out alive. Oh, and listening to a Dis-organizer literally telling him "Things to do todaytodaytoday: Die!"
The Time Traveler's Wife has moments like this. Towards the end of the book, there are some fairly depressing scenes, such as Henry discovering he will die in several years, or Charisse acknowledging Gomez's feeling towards Clare. This is followed by a fairly comical scene where Henry travels a few months into the future and ends up locked inside the library, which forces him to reveal his time traveling nature to the entire library staff. A few pages later, Henry almost freezes to death in another time-traveling incident, and ends up losing his feet. And let's not mention his death scenes....
Fools Crow by Richard Welch has a very strange ending: in the penultimate chapter, the main character Fools Crow (A Pikuni Blackfoot) finds a village of another band of Pikunis that had been slaughtered by white men. He reflects on the essential hopelessness of the Pikunis' situation with the white men. Previous chapters dealt with the ravaging of the Pikunis by smallpox. In the last chapter, Fools Crow and his tribe celebrate joyously a Blackfoot ceremony, the buffalo return, and everything is put back in equilibrium. Huh?
George Pelecanos' novel King Suckerman does a meta twist on Mood Whiplash: The book starts out as a light-hearted take on '70s exploitation films with a strong hint of Quentin Tarantino, with pop-culture riffs and catchphrase-spouting badass drug dealers and ex-cons. About halfway in, some of the characters go see a hotly anticipated blaxploitation flick (the titular King Suckerman) which abruptly ends on a depressing note. From that point on, the novel itself takes on a darker, more menacing shift of its own; the previously cool-seeming criminal characters turn out to be rather monstrously evil.
T. H. White's The Once and Future King starts as a light-hearted parody of Arthurian Legends, with anachronism, Merlin as a bumbling magician, Arthur turned into various animals and Pellinore's ineffectual quest for the Questing Beast. Slowly each following chapter has less and less humor and gets darker and darker, until the tragic last chapter that ends just before King Arthur's fight against his son Mordred as he reminisces over the good old days.
The Reynard Cycle: The entire series hinges around this. Many readers are cheering for Reynard by the end of the first book. By the end of the third...
Mark Twain's works often suffer from this, the most notable example occurring in The Adventures of Huckleberry Finn where we are treated to a humorous drunk, a cold-blooded murder, an attempted lynching, and then a circus, all literally in the same chapter.
A Connecticut Yankee in King Arthur's Court is particularly egregious, since the mood whiplash effect arguably results in an Out-of-Genre Experience. The book goes from a scene where Sandy actually thinks a pig farmer is really a bunch of 12-foot tall ogres and the pigs are captive princesses (which is a laugh out loud hilarious scene) to a gut-wrenching description of slavery. It feels like going from a Discworld type absurdist satire (or a Don Quixote misadventure) to high drama.
In The Dresden Files, this is usually because of Harry's sense of humor. Once, Nicodemus has him in a totally inescapable position, giving him the opportunity to join him—and if he refuses, Nick will just cut his throat after he finishes his breakfast. Harry promptly cracks a Spider-Man joke, and when Nicodemus is a bit nonplussed, says, "Must be a DC Comics fan."
Codex Alera often manages this by juxtaposing a Funny Moment with a serious scene. The most spectacular example is at the beginning of Princeps' Fury when we're treated to some hilarious bickering between a couple of soldiers. Then they're attacked by the Vord, and one is ripped into little bits while the other has to be Mercy Killed by Ehren.
Bridge to Terabithia: The book (and by extension, the movie) starts out relatively lighthearted and without drastic conflict... and ends up becoming completely tragic and melancholic following the revealing of Leslie's death. The same pattern can be seen in similar works, such as A Taste of Blackberries.
Catch-22 practically runs on this trope. The author seems to have taken a particular liking to end chapters by revealing critical bits of information that cause the reader to re-evaluate the events of the chapter, which had up till then been Played for Laughs, in a much more sinister light.
In particular, the various ridiculous bureaucratic rules Air Force members have to follow are played for dark laughs throughout the vast majority of the story. Then all of a sudden, in the wham chapter "The Eternal City," one such rule allows the sociopathic Captain Aardvark to get away with rape and murder. This is the final push the hero needs to get the Hell out of Dodge.
Book five of Virgil's Aeneid. The first half describes the funeral games for Anchises, in a generally light-hearted and sometimes humourous manner, ending with a running race in which the contestants start tripping each other up and get into an argument about who really won, which Aeneas cheerfully settles by bringing out extra prizes for those who feel cheated. He then gets the news the Trojan woman have become so disillusioned and tired of the constant travelling that they have set fire to his fleet, leading to his emotional low point - even his own people have now turned against him - and the realisation that he must now descend into the world of the dead.
Kids' novel Jennifer the Jerk is Missing. Starts out very suspenseful, with an 8-year-old boy who has a reputation for telling tall tales and being a brat, trying his best to convince his 13-year-old babysitter that he did, in fact, witness the kidnapping of his 8-year-old classmate, bratty Jennifer "the Jerk". Played totally for suspense for the first half of the story, but things start to get silly when Jennifer is encountered. Bound to a chair and gagged, she actually lets out a muffled bratty "ha ha" under her gag when her rescuers mess up, and things just mostly get sillier from there. One of the kidnappers even merely pretends to have a gun by pointing his finger through his pocket (and Jennifer can even tell). Totally shoots the suspense in the first half of the book to pieces. (Then later, it starts taking itself seriously again.)
Yoda: Dark Rendezvous alternates a much sillier-than-standard Master Yoda with reminders that a war is going on. A set of undercover Jedi suffering through transit on a ship belonging to a cut-rate cruise line, having to deal with things like an overexcited fire alarm system and a mazelike ship structure, turns heart-breakingly tragic when Asajj Ventress comes in and starts trying to kill the main cast. And anyone between her and them.
Aaron Allston's run in the X-Wing Series can tend towards this at times, but it helps that he does use transitional devices, and much of the silly is a deliberate in-universe attempt to raise morale.
In The Giver, there is a nice scene where Jonas watched his father give the smaller of infant twin brothers a check-up. It's so nice and lovely, and... Wait, that's that needle? What do you mean "can't have two identical people running around?" WHAT DO YOU MEAN "THE VEINS IN YOUR ARM ARE TOO TEENY-WEENY?!?!"
The Watsons Go to Birmingham—1963 starts out as a light-hearted family comedy told from the perspective of a boy living in Michigan. However, in the last couple of chapters the boy has a traumatizing brush with death when he nearly drowns in a whirlpool, and the family's titular road trip to Birmingham ends with them witnessing the infamous 1963 church bombing, which makes them fear that their youngest daughter has been killed. Fortunately, she's okay.
MASH Goes to Maine is mostly about a charmingly eccentric cast cheerfully bending the rules and beating the odds. Then you get to the story-within-the-story "The Sound Of The Moose"...
Rudyard Kipling uses it to great effect in "The Young British Soldier": set up like a drinking song, the poem starts out as a darkly humorous treatment of things like alcohol, cholera, and cheating wives. Then the last stanza hits like a punch to the gut.
When you're wounded and left on Afghanistan's plains, / And the women come out to cut up what remains / Jest roll to your rifle and blow out your brains, / And go to your Gawd like a soldier.
In-universe example in The Witcher. Geralt says of Dandelion (an accomplished bard and poet) that the latter's talent generally lies in ability to enact abrupt swings between touching lyrics and bawdy obscenity.
Transformers: Wings of Honor: Flames of Yesterday (a text story) pokes fun at the idea of gender, and the unruliness of the teams, then the Decepticons show up. This is especially noticeable with their weapons, high pressured water-guns that shoot chemicals. They shoot Metalhawk (after realizing that their guns are pump action), and he goes into crazy ramblings about colored rabbits. One shoots the head scientist with a more concentrated pressurized blast, that, coupled with her lack of armor, nicks her laser-core and kills her.
Honor Harrington pulls this twice in a single chapter. Honor's return to Grayson starts out very lighthearted, with Protector Benjamin trolling Admiral Matthews by dropping the revelation of Honor's return. This mood continues when she personally meets with Benjamin... then it shifts on one word: "Momma?" And then we're into tears of happiness as Honor is reunited with her parents, gradually shifting back into lightheartedness as Honor meets her brother and sister. Then Nimitz and Samantha are reunited... and the tone shifts suddenly to shock as they realize that Nimitz has been rendered telepathically mute.
French playwright Marcel Pagnol's childhood memories, 'My father's glory' & 'My mother's castle', definitely qualify. The two books are highly enjoyable tales of Pagnol's discovery of the countryside as a child in the 1900s, his admiration for his father, his love for his mother, his adventures with his brother and the birth of his friendship with a country boy. In the last chapters, the story goes from a joyous Summer dinner to young Marcel following a hearse and a list of all the tragedies which subsequently happened: Pagnol's mother died very young, only a few years after the events of the books, his childhood best friend was killed at barely 20 in the first world war, and his younger brother decided to stay in the countryside and died at age 30. "Thus is the life of a man. A few moments of happiness, quickly erased by unforgettable sadness."
At one point in the Relativity story "Let It Snow" (which is mostly flashbacks used to flesh out some of the main characters' backstories), Sara is reminiscing about Christmas when she was four years old. First, she opened her birthday present (her birthday is two days before Christmas), then she helped her older sister bake cookies, then her father came home and beat up her mother.
In The Count of Monte Cristo, the young women Eugenie and Louise are planning their escape from the French aristocracy. It's a tense, risk-filled scene...until Eugenie swears, and the two erupt in laughter.
In The Fault in Our Stars, the day after Hazel and Augustus share their first kiss and make love, Augustus reveals that his cancer has returned and metastasized.
It's not usual for the characters in Uncommon Animals make jokes in dark moments, but the first story, The Hunted, goes from Mina and Jennelle drooling over the 'delivery boy' to Mina being terrified of him in the space a sentence.
Due to the nature of the series, it's rather frequent in Redwall for the prose style to switch back and forth between jovial J. R. R. Tolkien and ruthless George R. R. Martin for a few pages, or even paragraphs. For example, at one point in Mossflower, the heroes need to outsmart two dimwitted villains, so they pull the old trick also seen in The Hobbit of starting an argument among them by imitating voices, leading them to comically quarrel over their cheese. One of them then fatally impales the other in his anger, then in shock at what he's done, stumbles backward into a sinkhole and drowns. Our protagonists then sing a happy little song about this as they carry on.
Robert Browning's poem "Porphyria's Lover" begins on a stormy night when the speaker, alone in a dark and dreary cottage, is visited by a woman who he believed had rejected him, who has deserted a party and walked through the rain to find him. She lights a fire in the grate, leans on his shoulder, and confesses that she has loved him all along. Eager to preserve this beautiful moment, he strangles her in her own hair.
In Fred Vargas' Wash This Blood Clean From My Hand, Adamsberg's telling of the story of Judge Fulgence starts very ominously... But when Adamsberg off-handedly mentions that another kid he knew used to throw blown-up toads into Fulgence's garden, Danglard spends an entire page asking how you can blow up toads (by putting cigarettes in their mouth). It's made even funnier by the fact that it's usually Adamsberg who gets sidetracked.
A much darker example is from The Slow Regard of Silent Things, a whimsical story told from Auri's point of view. The first few chapters show her going about her business, meditating on the universe, etc. Then the following chapter is one line:
"On the third day, Auri wept."
Isaac Asimov's "Rejection Slips": The rejection and rhyming of the first two letters are very clear, then comes the irregular rhyming and effusively complimentary poem, which needs a postscript to actually convey the rejection.