וְאַתֶּ֕ם חֲשַׁבְתֶּ֥ם עָלַ֖י רָעָ֑ה אֱלֹהִים֙ חֲשָׁבָ֣הּ לְטֹבָ֔ה לְמַ֗עַן עֲשֹׂ֛ה כַּיּ֥וֹם הַזֶּ֖ה לְהַחֲיֹ֥ת עַם־רָֽב׃
And as for you, ye meant evil against me; but God meant it for good, to bring to pass, as it is this day, to save much people alive.
Read halakhic rulings (Jewish law) on Genesis 50:20: and classical halakhic sources.