It now means exactly what you say, something surprising. The origin is in horse racing, where the book was the record of bets laid on a race kept by a bookmaker. So when a horse performed in a way that nobody expected, so that most bets lost, it was something that benefited the book and so the bookmaker.