a blessing in disguise
US /ə ˈblɛsɪŋ ɪn dɪsˈɡaɪz/
UK /ə ˈblɛsɪŋ ɪn dɪsˈɡaɪz/

1.
something that seems bad or unlucky at first, but later turns out to be beneficial
:
•
Losing that job was a blessing in disguise; it pushed me to start my own business.
•
The cancelled flight turned out to be a blessing in disguise, as we avoided a major storm.