"God sent me before you to preserve for you a remnant on earth, and to keep alive for you many survivors. So it was not you who sent me here, but God; he has made me a father to Pharaoh, and lord of all his house and ruler over all the land of Egypt."
Even our basic acts and choices—such as Joseph's brothers' decision to sell him into slavery—can have a positive spiritual consequence if they're approached with the right consciousness. Joseph is able to recognize that, despite their negative intention, the brothers were in fact acting to accomplish good in the world. Of course, if Joseph had chosen to hang on to resentment and anger, the results would have been very different.