And the LORD was with Joseph, and he was a prosperous man; and he was in the house of his master the Egyptian. And his master saw that the LORD was with him, and that the LORD made all that he did to prosper in his hand. Genesis 39:2-3
Arriving in Egypt, Joseph was sold to Potiphar, captain of the king's guard, in whose service he remained for ten years. He was here exposed to temptations of no ordinary character. He was in the midst of idolatry. The worship of false gods was surrounded by all the pomp of royalty, supported by the wealth and culture of the most highly civilized nation then in existence. Yet Joseph preserved his simplicity and his fidelity to God. The sights and sounds of vice were all about him, but he was as one who saw and heard not. His thoughts were not permitted to linger upon forbidden subjects. The desire to gain the favor of the Egyptians could not cause him to conceal his principles. Had he attempted to do this, he would have been overcome by temptation; but he was not ashamed of the religion of his fathers, and he made no effort to hide the fact that he was a worshiper of Jehovah. . . . Potiphar's confidence in Joseph increased daily, and he finally promoted him to be his steward, with full control over all his possessions. . . .
The marked prosperity which attended everything placed under Joseph's care was not the result of a direct miracle; but his industry, care, and energy were crowned with the divine blessing. Joseph attributed his success to the favor of God and even his idolatrous master accepted this as the secret of his unparalleled prosperity. Without steadfast, well-directed effort, however, success could never have been attained. God was glorified by the faithfulness of His servant. It was His purpose that in purity and uprightness the believer in God should appear in marked contrast to the worshipers of idols--that thus the light of heavenly grace might shine forth amid the darkness of heathenism.
Joseph's gentleness and fidelity won the heart of the chief captain, who came to regard him as a son rather than a slave. The youth was brought in contact with men of rank and learning, and he acquired a knowledge of science, of languages, and of affairs--an education needful to the future prime minister of Egypt.