The Jataka, Vol. II, tr. by W.H.D. Rouse, , at sacred-texts.com
"As when a pair of shoes," etc.--This story the Master told in the Bamboo Grove, about Devadatta. The Brethren gathered together in the Hall of Truth, and began to discuss the matter. "Friend, Devadatta having repudiated his teacher, and become the foe and adversary of the Tathāgata, has come to utter destruction." The Master came in, and asked what they were talking about as they sat there. They told him. The Master said, "Brethren, this is not the first time that Devadatta has repudiated his teacher, and become my enemy, and come to utter destruction. The same thing happened before." Then he told them an old-world tale.
Once on a time, while Brahmadatta was king of Benares, the Bodhisatta was born as the son of an elephant trainer. When he grew up, he was taught all the art of managing the elephant. And there came a young villager from Kāsi, and was taught of him. Now when the future Buddhas teach any, they do not give a niggardly dole of learning; but according to their own knowledge so teach they, keeping nothing back. So this youth learnt all the branches of knowledge from the Bodhisatta, without omission; and when he had learnt, said he to his master: 
"Master, I will go and serve the king."
"Good, my son," said he: and he went before the king, and told him how that a pupil of his would serve the king. Said the king, "Good, let him serve me." "Then do you know what fee to give?" says the Bodhisatta.
"A pupil of yours will not receive so much as you; if you receive an hundred, he shall have fifty; if you receive two, to him shall one be given." So the Bodhisatta went home, and told all this to his pupil.
"Master," said the youth, "all your knowledge do I know, piece for piece. If I shall have the like payment, I will serve the king; but if not, then I will not serve him." And this the Bodhisatta told to the king. Said the king,
"If the young man could do even as you--if he is able to show skill for skill with you, he shall receive the like." And the Bodhisatta told this to the pupil, and the pupil made answer, "Very good, I will." "To-morrow," said the king, "do you make exhibition of your skill." "Good, I will; let proclamation be made by heat of drum." And the king caused it to be proclaimed, "To-morrow the master and the pupil will
make show together of their skill in managing the elephant. To-morrow let all that wish to see gather together in the courtyard of the palace, and see it."
"My pupil," thought the teacher to himself, "does not know all my resources." So he chose an elephant, and in one night he taught him to do all things awry. He taught him to back when bidden go forward, and to go on when told to back; to lie down when bidden rise, and to rise when bidden lie down; to drop when told to pick up, and to pick up when told to drop.
Next day mounting his elephant he came to the palace yard. And his pupil also was there, mounted upon a beautiful elephant. There was a great concourse of people. They both showed all their skill. But the Bodhisatta made his elephant reverse orders;  "Go on!" said he, and it backed; "Back!" and it ran forward; "Stand up!" and it lay down; "Lie!" and it stood up; "Pick it up!" and the creature dropped it; "Drop it!" and he picked it up. And the crowd cried, "Go to, you rascal! do not raise your voice against your master! You do not know your own measure, and you think you can match yourself against him!" and they assailed him with clods and staves, so that he gave up the ghost then and there. And the Bodhisatta came down from his elephant, and approaching the king, addressed him thus--
"O mighty king! for their own good men get them taught; but there was one to whom his learning brought misery with it, like an ill-made shoe;" and he uttered these two stanzas:--
"Even so an underbred ignoble man,
Having learnt all that he can learn from you,
By your own teaching proves your very bane 1:
The lowbred churl is like the ill-made shoe."
 The king was delighted, and heaped honours upon the Bodhisatta.
When this discourse was ended, the Master identified this Birth as follows:--"Devadatta was the pupil, and I myself was the teacher."
155:1 The schol. would take tam as for attānam, "he hurts himself," not "thee," but this is hardly possible. The verses do not seem to fit the story very exactly.