The following excerpt is taken from Nicole Riggs' new book on the Shangpa Lineage, Like An Illusion: Lives of the Shangpa Kagyu Masters
In the past, Avalokitesvara the noble Great Compassionate One, engendered great aspiration. For countless aeons, he gathered the two accumulations, attained the tenth level of a bodhisattva, and obtained the Great Light Rays Empowerment. He entered the ranks of the sons and daughters of the Buddha by sealing his aspiration with the following vow: "I shall benefit beings in this samsaric world and throughout the ten directions. I shall remain in this samsaric world to liberate all sentient beings from suffering and until every one of them has attained supreme enlightenement, I myself shall not pass into nirvana. And if I ever break this vow, may by body be shattered into a thousand pieces!"
Avalokitesvara stayed at Mount Potala. He performed emanations at every moment and brought to maturation and liberation countless beings, in ways far too vast for us to express. This he did for a great many aeons, until one day he thought he should see what development had happened given the many beings he had led to maturation and liberation.
With his clairvoyance, he exerted his gaze on the world and saw that the realm of sentient beings was more confused than ever. Peoples' lives were getting shorter, they were mired in the five dregs and it was difficult for beings to avoid doing evil.
He thought, "I haven't succeeded in liberating even a single sentient being!" This thought broke his vow, and consequently, his body split into a thousand pieces.
Buddha Amitabha now appeared and said to Avalokitesvara, "Oh noble son, you have broken your vow, that is not good! Now, you'd better renew your resolution, and in stronger terms this time!"
After he finished speaking, Amitabha took the thousand pieces and fashioned eleven faces and a thousand arms. Then, he blessed Avalokiteshvara who now thought, "There is no possible way for me to renew my vow more strongly than I did originally." So for the next seven days, he remained in a daze [of uncertainty].
When he came to, he perceived that by means of a wrathful form, he could train sentient beings mired in the five dregs. Seeing that even those who practiced Dharma were haunted by fears of the bardo, he recognized that in a wrathful form, he could protect them from the frights of the bardo. Lastly, observing that the beings of this degenerate age were poor and needy, and experienced only suffering, he discerned that by means of a wrathful form, he could provide them with an antidote to their suffering; their needs and desires would be answered simply by expressing their wishes. Through this three-fold activity, Avalokitesvara was able to renew his vow in ways even more powerful than before and this was crystallized as the black-blue syllable HUNG at his heart, which transformed into the swift wisdom-protector.
The earth shook in six ways in respect to Avalokitesvara's compassionate aspiration. Buddha Amitabha, together with countless Buddhas, bodhisattvas of the ten levels and the like exclaimed with one voice, "Oh noble son! This is a noble aspiration indeed! You shall have the powers of all the dakinis.You shall have the strength of Yamantaka. And spirits, demons, harm-doers, and gods will perform activity [on your behalf]."
Thus the great wrathful emanation was granted the empowerments of the body, speech, mind, qualities and activity of all the Buddhas of the three times. As of that time, Mahakala has remained guardian of the teachings in all the Pure Lands.
A full account of Mahakala ends the stories in Like an Illusion: Lives of the Shangpa Kagyu Masters. Details on the book are available here.