Pull a Rabbit out of the Hat
To do something that is unexpected.
M. Night Shyamalan pulled a rabbit out of the hat with the surprise twist in “The Sixth Sense”.
Did you know?
This idiom takes a leaf out of the common magic trick and is also sometimes used to refer to a surprising solution to a problem.