Raiders of The Lost Ark is, for the first 95% of the runtime, an action-adventure with no supernatural events. There are a few fantasy elements like an ancient temple where all the traps still work, but there isn't magic.
Then at the end God appears with a bunch of angry ghosts and kills all the bad guys. Not, like, "a" god. Like the movie is extremely explicit that this is specifically the Hebrew God, the Abrahamic one, Hashem, the Big Guy. Nothing in the previous hour and 45 minutes mattered at all; God shows up and resolves the plot by doing a miracle.
And people loved it. I love it. This movie is a classic. (I mean, what a gift to Hebrew school sleepover nights.) Even the ending is a classic. People don't talk about feeling like the ending is "cheap" or "cheating." They talk about how those Nazis' faces melted off their freakin skulls.
I feel like there's some sort of lesson here about taking too much writing advice that's like "always make sure your payoff is justified by your setup," and not enough that's like "always make sure your payoff is just, like, totally freakin righteous dude"
While there are no explicitly supernatural elements in the film until the ending, there is an aura established very early on and maintained consistently that the Ark of the Covenant is not something anyone should be fucking with.
Right at the beginning of the film, when Indiana is trying to explain what the Ark is to the government men who've come for his help, he pulls up an ancient illustration and tries to glaze over the fact that the Hebrews apparently believed the Ark contained the power to eviscerate people. And though he waves it off as superstition, it is clear that Hitler and the Nazis desire the Ark because they genuinely believe that the Ark can give them the power of God.
Everyone around Indiana is extremely trepidatious about the entire concept of going after the Ark, leaving him seeming almost too confident in his rejection of the supernatural. The puzzles and trials he has to go after feel like they border on the magical. The map room? Where you mount an ancient gem on a rod, place it in the right spot at the right time of day, and the sun's light will refract with blinding intensity and precision on the precise location of the Ark? Yeah that's some biblical shit. The Ark's tomb, completely infested with snakes as if nature itself is warding off anyone who dares to enter it? Biblical shit. It's all plausibly realistic, but in the context of everyone else's supernatural anxieties surrounding the Ark, it reinforces the idea in the viewer's mind that there may be something mystical going on.
In the Hebrew texts, God cursed the Ark so that anyone who touched it, intentionally or not, was killed instantly. Just, bam, dead. And you may have noticed, in the film, nobody ever actually directly touched the Ark. They slide wooden beams into it and carry it around that way. That's also how they lift the lid off of it. They never actually lay a finger on it. This is, of course, reasonable for the characters - to Indi it's an ancient biblical artifact of great historical significance, he wouldn't dare smudge it with a fingerprint. In this way it manages to maintain nearly total scriptural accuracy, right up to the very end.
And lastly, of course, there's a scene about 10 minutes before the climax of the film. Indiana and Raven have just finished their comedic romantic bit in their submarine quarters and are presumably taking a well deserved rest, before the vessel is commandeered by the Nazis. We cut to the cargo hold, somewhere deep in the submarine, in some shady corner. The Ark is still boxed up in a wooden crate emblazoned with swastikas, just recently liberated from the Nazis by Indiana. A rat is sniffing around on the floor right next to the crate. It suddenly begins to squeal and writhe. We see in detail as it contorts in a peculiar manner, as if seizing. Something is severely affecting the creature. A deep, ominous hum begins to emanate from the crate. The swastika begins to smoke, and a burn mark begins to spread outwards from the center. The film hard cuts away as the Nazis board the submarine and the action with our characters resume, but the scene fulfilled it's purpose and ingrained in the viewer's mind, just in time, that the Ark is definitely, absolutely, supernatural. The next time we see the crate, the nazi iconography has been completely scorched off, it's just covered in black spots. God hates nazis, hell yeah! No character ever addresses this - there are other things on their minds at the moment. But we notice it. And we know what caused it.
All of this to say that when the Nazis finally open the thing and God makes their faces melt, turns them into raisins, explodes their heads, and electrocutes them until They're Only Carbon Now™, it doesn't come out of left field! It has been meticulously set up from the very beginning of the film, the mood of mysticism and eerie biblical dread hammered home in every scene dealing with the Ark, it almost feels like the movie couldn't have concluded any other way.
The Deus Ex Machina, despite its literal latin translation, doesn't apply here. As a critical concept, it's specifically about story resolutions that are unearned, unexplained, and never set up. If no character had ever spoken of the Ark in a religious or supernatural context, Hitler only wanted it because it would look nice in his parlor, that French guy was using it as a bench before the climax, and we never got that scene with the rat in the cargo hold, the resolution would have really felt like it came out of left field. But because it was properly established in the story - not directly (until like 10 minutes before the end), but thematically - it all comes together in the end.
Mood and atmosphere are as important to your story's coherence and believability as the direct narrative events within it.