Have Something in the Bag

What does the idiom “have something in the bag” mean?

Definition: Be certain to win

Example: We thought we had the match in the bag, but we didn’t realize our opponents’ star striker would be healthy again and ready to play.