Genesis 45:5 (NKJV)
But now, do not therefore be grieved or angry with yourselves because you sold me here; for God sent me before you to preserve life.

Joseph could see the hand of God in all his pain looking back. You will be able to see it too, soon, looking back.