Pull a rabbit out of a hat

1. To succeed when you were expected to fail.