pull one out of the hat

pull one out of the hat

bring off an unexpected trick in an apparently desperate situation.
The image here is of a rabbit pulled out of a magician's hat.
1971 James McClure The Steam Pig I must say you've really pulled one out of the hat this time.
See also: hat, of, one, out, pull