The difficulty with tonal shifts are their disruptive potential. A story may be chugging along nicely when out of nowhere a stereotypical romance turns into a survival horror. The key to pulling this off is foreshadowing. Only by keying the reader in on what could come can the reader get through a tonal shift without being entirely surprised or turned off.
Foreshadowing a tonal shift could come in the form of a scene, a chapter, a piece of dialogue, or even some backstory which is still firmly rooted in the current tone but alludes to a different tone or set of themes. Take the romance/horror example. Two characters could be discussing a steamy, rumored affair between a supporting character and another character who will become the bloodthirsty antagonist. This conversation has all the markings of dialogue out of a romance novel, but one character mentions he was once convicted of stalking, or that he is rumored to have been abusive with a former partner. In the moment, this amounts to nothing more than a rumor, but it does inform the reader that such topics and themes are fair game in this story.
Of course, tonal shifts do not always need to be so drastic and immediate. Take the Lord of the Rings for example (I'll use the movies, given the tonal shift is much more clear). The initial backstory is dark and brooding, introducing a terrible and unfathomable evil and widespread bloodshed. Cut to the shire, where the Hobbits attend Bilbo's birthday party with singing, dancing, and fireworks. When the story shifts back to that darker tone following Frodo receiving the Ring, it's not so jarring. Imagine if the movie started in the Shire, without any backstory. That would be much more jarring!
In your case, you might utilize a darker take on your world's history to foreshadow your shift. You can still retain a lighthearted atmosphere, but drop in one or several sobering flashbacks or discussions of the darkness that is to come. Personally, I think fantasy is ripe for such a technique given reader expectations of battle/death/dark magic in most fantasy settings.