I tried on google every word and phrase I could come up but I just couldn't find it. I'm pretty sure I've seen this word before and it's english.
I think that a blessing in disguise may fit your description :
something that seems bad or unlucky at first, but results in something good happening later:Losing that job was a blessing in disguise really.
salutary ... (especially with reference to something unwelcome or unpleasant) producing good effects; beneficial.
J.R.R. Tolkien coined the word eucatastrophe, and I think it would match the word you’re looking for.
eucatastrophe A sudden and favourable resolution of events in a story; a happy ending.