וְהַ֨מְּדָנִ֔ים מָכְר֥וּ אֹת֖וֹ אֶל־מִצְרָ֑יִם לְפֽוֹטִיפַר֙ סְרִ֣יס פַּרְעֹ֔ה שַׂ֖ר הַטַּבָּחִֽים׃ (פ)
And the Midianites sold him into Egypt unto Potiphar, an officer of Pharaoh’s, the captain of the guard.
Read kabbalistic (mystical) interpretation of Genesis 37:36: and classical mystical sources.