If I'm remembering right, in a previous life of the Buddha, because dharma teachings were so rare at that time, a being offered to give a teaching, but only if he sacrificed his life to this being.
What is the text and reference for this?
Buddhism Stack Exchange is a question and answer site for people practicing or interested in Buddhist philosophy, teaching, and practice. It only takes a minute to sign up.Sign up to join this community
There are 5 stories that I’ve managed to found which fit your description. Each story follows the same structure: a previous incarnation of the Buddha was privileged or successful, he yearned for the Dharma but was unable to find a great teacher. A celestial being (or enlightened or both) in disguise would appear before the would-be Buddha and require him to sacrifice himself (or what/those he held dear) in order to acquire the teaching. Each incarnation got the teaching and performed the required feat, emerging unscathed afterwards. Here are the names of each incarnation (Chinese/Vietnamese) and what they have to do:
All 5 stories can be found in the Taisho edition of the 賢愚經, roughly translated as Sutta on the Fool and the Wise. The Sutta, although sharing the same name with the Bālapaṇḍita Sutta, is drastically different from the latter since the Bālapaṇḍita Sutta contains none of the above stories. I’m not a Buddhist scholar and my Chinese is inadequate, so I’m not sure what is the original spellings of these transliterated names. Consequently, I couldn't provide the names in Sanskrit or Pali.
I did ponder whether these stories were fabricated as they seem to be less well-known in Theravada circles. This doesn’t seem to be the case as:
This implies that the stories can also be found in Vajrayana traditions, not just Mahayana, and have circulated for millenia. They were supposed to be treated as Jataka stories, but somehow ended up not being so.
Upon more digging, I found out that there exists an English translation from Mongolian of this whole sutra. It's a book called Sutra of the Wise and the Foolish by Stanley Frye. You can preview the book on Google Books. The first chapter (pg. 1-13) contains all of the stories I mentioned above.
The Buddha, who was actually a Bodhisattva in that particular tale, sacrificed himself before a starving tiger who was just about to eat her newborns. This was a compassionate response to the situation, or one might use the term loving-kindness.
13-15. Now, below in a cavern of the mountain, he beheld a young tigress that could scarcely move from the place, her strength being exhausted by the labour of whelping.
Her sunken eyes and her emaciated belly betokened her hunger, and she was regarding her own offspring as food, who thirsting for the milk of her udders, had come near her, trusting their mother and fearless; but she brawled at them, as if they were strange to her, with prolonged harsh roarings.
16, 17. On seeing her, the Bodhisattva, though composed in mind, was shaken with compassion by the suffering of his fellow-creature, as the lord of the mountains (Meru) is by an earthquake.
It is a wonder, how the compassionate, be their constancy ever so evident in the greatest sufferings of their own, are touched by the grief, however small, of another!
And his powerful pity made him utter, agitation made him repeat to his pupil, the following words manifesting his excellent nature: “My dear, my dear,” he exclaimed,
“Behold the worthlessness of Saṁsāra! This animal seeks to feed on her very own young ones. Hunger causes her to transgress love’s law.
Alas! Fie upon the ferocity of self-love, that makes a mother wish to make her meal with the bodies of her own offspring!
Who ought to foster the foe, whose name is self-love, by whom one may be compelled to actions like this?
Go, then, quickly and look about for some means of appeasing her hunger, that she may not injure her young ones and herself. I too shall endeavour to avert  her from that rash act.”
The disciple promised to do so, and went off in search of food. Yet the Bodhisattva had but used a pretext to turn him off. He considered thus:
- “Why should I search after meat from the body of another, whilst the whole of my own body is available? Not only is the getting of the meat in itself a matter of chance, but I should also lose the opportunity of doing my duty.
22-24. This body being brute, frail, pithless, ungrateful, always impure, and a source of suffering, he is not wise who should not rejoice at its being spent for the benefit of another.
There are but two things that make one disregard the grief of another: attachment to one’s own pleasure and the absence of the power of helping. But I cannot have pleasure, whilst another grieves, and I have the power to help; why should I be indifferent?
And if, while being able to succour, I were to show indifference even to an evildoer immersed in grief, my mind, I suppose, would feel the remorse for an evil deed, burning like shrubs caught by a great fire.
- Therefore, I will kill my miserable body by casting it down into the precipice, and with my corpse I shall preserve the tigress from killing her young ones and the young ones from dying by the teeth of their mother.
Good householder, not being aware of such - also: who would had taught the Dhamma when there is no? - here maybe the root of idea:
There is a famous Jataka where the Bodhisatta was a rabbit and a hermit dwelked in the forest. All animals giving alms, the rabbit thought that grass wouldn't be proper to give and he decided to sacrifices himself as food. As he jumped into the fire to grill himself, the King of Devas made it that he wasn't burned at all.
This story, as a teaching of how eager one should try to give alms to ascetics, is celebrated as the "Rabbit in the moon" on Anapanasati-day, the end of ling Vassa in South-East Asia.
Teaching, being taught, of the Dhamma requires relation, Upanissaya: giving is the way of building up relation. In this way the Bodhisatta increased his Nissaya toward recluses, pacceka Buddhas, monks, later way to find the Dhamma within right lifelihood by himself.