Deus ex machina. Literally, “god from the machine.”
You’ve seen it before. It’s the object that turns up exactly at the perfect time the characters need it to get out of their life-threatening fix. It’s the character who suddenly remembers they studied Morse code in Boy Scouts and translates the message that sends them in the right direction. It’s the tornado that swoops out of the cornfield and kills off the bad guy just as he’s about to kill the hero and heroine.
It’s also weak storytelling and should be avoided at all costs.
If you paint (or in this case, write) yourself into a corner, you don’t resort to magic wands to fix it. (Unless, of course, it’s a story about wizards.) You might, however, be forced to send your story in a different direction than you wanted.
Your other option, of course, is to stop, examine your story from the beginning, and make course corrections to avoid the problem in the first place, or set it up better so it’s not a, “And, SUDDENLY…!” kind of moment.
Writing How-To: "And then, suddenly…"