The Jataka, Volume I, tr. by Robert Chalmers, , at sacred-texts.com
"Let great and small."--This story was told by the Master while at Jetavana, about Anātha-piṇḍika's true friend. For his acquaintances and friends and relations came to him and tried hard to stop his intimacy with a certain man, saying that neither in birth nor wealth was he Anātha-piṇḍika's equal. But the great merchant replied that friendship should not depend on equality or inequality of externals. And when he went off to his zemindary, he put this friend in charge of his wealth. Everything came to pass as in the Kālakaṇṇi jātaka 1. But, when in this case Anātha-piṇḍika related the danger his house had been in, the Master said, "Layman, a friend rightly so-called is never inferior. The standard is ability to befriend. A friend rightly so-called, though only equal or inferior to one's self, should be held a superior, for all such friends fail not to grapple with trouble which befalls one's self. It is your real friend that has now saved you your wealth. So in days gone by a like real friend saved a Sprite's mansion." Then at Anātha-piṇḍika's request, he told this story of the past.
Once on a time when Brahmadatta was reigning in Benares, the Bodhisatta was born a Sprite in the king's pleasaunce, and dwelt in a clump of kusa-grass. Now in the same grounds near the king's seat there grew a beautiful Wishing Tree (also called the Mukkhaka) with straight stem and spreading branches, which received great favour from the king. Here dwelt one who had been a mighty deva-king and had been reborn a Tree-sprite. And the Bodhisatta was on terms of intimate friendship with this Tree-sprite.
Now the king's dwelling had only one pillar to support the roof
and that pillar grew shaky. Being told of this, the king sent for carpenters and ordered them to put in a sound pillar and make it secure. So the carpenters  looked about for a tree that would do and, not finding one elsewhere, went to the pleasaunce and saw the Mukkhaka. Then away they went back to the king. "Well," said he, "have you found a tree that will do?" "Yes, sire," said they; "but we don't like to fell it." "Why not?" said the king. Then they told him how they had in vain looked everywhere for a tree and did not dare to cut down the sacred tree. "Go and cut it down," said he, "and make the roof secure. I will look out for another tree."
So they went away. And they took a sacrifice to the pleasaunce and offered it to the tree, saying among themselves that they would come and cut it down next day. Hearing their words, the Tree-sprite knew that her home would be destroyed on the morrow, and burst into tears as she clasped her children to her breast, not knowing whither to fly with them. Her friends, the spirits of the forest, came and asked what the matter was. But not one of them could devise how to stay the carpenters' hand, and all embraced her with tears and lamentations. At this moment up came the Bodhisatta to call upon the Tree-sprite and was told the news. "Have no fear," said the Bodhisatta cheerfully. "I will see that the tree is not cut down. Only wait and see what I will do when the carpenters come to-morrow."
Next day when the men came, the Bodhisatta, assuming the shape of a chameleon, was at the tree before they were, and got in at the roots and worked his way up till he got out among the branches, making the tree look full of holes. Then the Bodhisatta rested among the boughs with his head rapidly moving to and fro. Up came the carpenters; and at sight of the chameleon their leader struck the tree with his hand, and exclaimed that the tree was rotten and that they didn't look carefully before making their offerings the day before. And off he went full of scorn for the great strong tree. In this way the Bodhisatta saved the Tree-sprite's home. And when all her friends  and acquaintances came to see her, she joyfully sang the praises of the Bodhisatta, as the saviour of her home, saying, "Sprites of the Trees, for all our mighty power we knew not what to do; while a humble Kusa-sprite had wit to save my home for me. Truly we should choose our friends without considering whether they are superiors, equals, or inferiors, making no distinction of rank. For each according to his strength can help a friend in the hour of need." And she repeated this stanza about friendship and its duties:--
Thus did she teach the assembled devas, adding these words, "Wherefore, such as would escape from an evil plight must not merely consider whether a man is an equal or a superior, but must make friends of the wise whatsoever their station in life." And she lived her life and with the Kusa-sprite finally passed away to fare according to her deserts.
His lesson ended the Master identified the birth by saying, "Ānanda was then the Tree-sprite, and I the Kusa-sprite."
267:1 No. 83.