A blessing in disguise

Meaning: Something that seems bad at first but eventually turns out to be beneficial.

Example: Losing that job was a blessing in disguise because it led her to a much better career.