pull something/a rabbit out of the hat
pull a rabbit out of (one's)/the hat
To do something surprising and seemingly impossible; to produce something in a way that has no obvious explanation, as if done by magic. A reference to the clichéd magician's trick of pulling a live rabbit out of a seemingly empty hat. The caterers really pulled a rabbit out of the hat by producing 100 cupcakes with just 20 minutes' notice. Unless someone can pull a rabbit out of their hat, I just don't see how we can fix the issue without starting the whole thing over again from scratch.
pull something/a ˌrabbit out of the ˈhat(informal) suddenly produce something as a solution to a problem: We had almost given up hope when Mick pulled a rabbit out of the hat by coming up with a great new idea.
This is a trick that is often done by magicians.