Once Solomon had chained the demon king Ashmedai, he held him captive until the Temple was completed. When the work was done, the king grew curious. "What is your superiority over us," he asked, "if it is true, as it is written (Numbers 23:22), that God has the strength of a wild ox — which tradition says means ministering angels and demons alike?"
Ashmedai smiled the smile of one who knows he is about to be released. "Take this chain from my neck," he said, "and give me your signet ring, and I will show you." Solomon, to his sorrow, obeyed. No sooner did the demon have the ring than he seized the king, swallowed him, stretched out one wing touching heaven and the other the earth, and vomited Solomon forth four hundred miles away.
Stripped of his throne, Solomon wandered from door to door. Rav and Samuel disagreed about what he carried — one said his staff, the other said his water-jug. Wherever he came he declared (Ecclesiastes 1:12), I, Kohelet, was king over Israel in Jerusalem, and people laughed at him. Of this time he wrote (Ecclesiastes 1:3; 2:10), What profit hath a man of all his labor?
The Talmud (Gittin 68b) tells this story as a parable of pride. Solomon had conquered a demon, built a Temple, and held every secret of creation in his hand — and one moment's curiosity about evil sent him begging. Only when the Sanhedrin recognized him and restored him to his throne did he learn that even the wisest man's kingdom is held by a thread.