
Pull something/a rabbit out of the hat
Unexpected Solutions
This phrase often implies solving a problem in a surprising way that others did not anticipate. 
Last Minute
It suggests that the action or solution comes in a crucial moment, often when time is running out. 
Figurative Use
Remember, this is a metaphorical expression, not to be taken literally. No real hat or rabbit is involved. 