But note Joseph’s words: “it was not you who sent me here, but God” (Genesis 45:8). Neither treacherous siblings nor a woman’s lust nor the shame of prison nor a cupbearer’s neglect could thwart the purpose of God (Job 42:2) in preserving God’s people (Genesis 45:7) and fulfilling a prophecy given to Abraham (Genesis 15:13). God made evil the slave of his grace.
And he’s doing the same for you. God is doing more good than you can imagine through the most painful experiences of your life.
– Jon Bloom, “Your Sin Is No Match for God’s Grace” on Desiring God
(emphasis mine; I highly recommend reading the rest!)