Chapter 36 of 42 · Shata Rudra Samhita · Overall chapter 265 of 464
Avatara as Ashvatthama
Drona's austerities for an invincible son are answered by the birth of Ashvatthama as Shiva's own portion; during the Kurukshetra war, when Ashvatthama's brahmastra threatens both Arjuna and Uttara's unborn child, only an even greater weapon granted by Shiva - and Krishna's own recognition that Ashvatthama's violence serves Shiva's will - can counter it.
Nandishvara said
Sanatkumara, hear of the lord Shiva the supreme self's supreme avatara called Ashvatthama. Drona was born in Bharadvaja's line but not from a womb, as a portion of the wise Brihaspati, self-controlled, brave, supreme among bowmen, a brahmana rishi skilled in every kind of weapon, very energetic and extensive in his deeds, foremost among those who knew all weapons. The learned know he was skilled in both the Vedas and the science of archery. Drona was great and wonderful in his deeds and extended his own line. By his own strength he became the acharya of the Kouravas, counted among the Kouravas' six maharathas. To help the Kouravas he tormented himself with extensive austerities directed to Shiva. The supreme brahmana Dronacharya wanted a son. Bhagavan Shankara, kind to devotees, was pleased and came before Drona. Seeing him, Drona was satisfied and at once bowed, heart full of joy, head lowered and hands joined. Lord Shankara, satisfied by his praise and austerities, said, "Ask for a boon." Hearing Shambhu, Drona bowed and asked for a son born as his portion, strong and unconquerable before everyone. Hearing Drona, Shambhu said it would be so, and the lord, who plays and gives happiness, vanished. Very happy, with his doubts gone, Drona went home and gladly told his wife all that had happened.
After some time Rudra, the lord who destroys everything, was born in his portion as Drona's very strong son, famous on earth as Ashvatthama, brave, lotus-eyed, terrible, able to destroy the enemy's side. By his father's command, in the Bharata war, the strong one helped the Kouravas. By taking refuge in that very brave one, Bhishma and the other Kouravas became extremely strong, and even the heaven-dwellers could not beat them. The Pandavas were all skilled and very valiant, but, fearing him and their own destruction, could not defeat the Kouravas. So, instructed by Krishna, Arjuna undertook terrible austerities dedicated to Shambhu, got a supreme weapon as a boon and defeated them. The very brave Ashvatthama was born as Mahadeva's portion, yet out of his devotion he showed his own powers. The Pandavas' sons were very valiant and trained by Krishna and others, but he made the effort and destroyed them. The enemy could not counter his strength. Arjuna was disabled by grief for his son. Seeing Ashvatthama descend on him, Achyuta drove the chariot away. Ashvatthama released the weapon called brahmashira, and a terrible energy appeared in all directions. Seeing his life in danger, Arjuna was distressed, exhausted, very frightened, his energy gone, and said to Krishna that he did not know what this was or where it had come from, since the energy was advancing on him from all sides and was unbearable. Hearing Arjuna, Krishna, supreme among Shiva's devotees, meditated on Shiva and his wife and affectionately answered: know this is Drona's son's very energetic brahma weapon, and no other weapon can counter it. Quickly remember Shiva. Lord Shambhu protects his own devotees, and he gave you his supreme weapon that can accomplish every task. Destroy this weapon's energy with the greater energy of Shiva's weapon. Saying this, Krishna himself meditated on Shiva to accomplish the aim. Hearing Krishna, Partha remembered Shiva in his heart, bowed, touched water and released that weapon. The brahmashira weapon is invincible and cannot be countered, yet the energy of Shiva's weapon at once pacified it. One should not think this wonderful, for everything wonderful exists in Shiva, who has no origin and by his powers creates and destroys the entire universe.
Ashvatthama, born from Shiva's portion, understood all this. He was not distressed by what Shiva had done, since it was Shiva's wish and his mind was not dissatisfied. Drona's son decided that no Pandavas should be left on earth and resolved to destroy the child in Uttara's womb. Since the brahma weapon could not be countered by any other weapon, the great lord hurled the weapon's great radiance toward Uttara's womb. Uttara, Arjuna's daughter-in-law, was distressed and, scorched by the weapon, praised Krishna, Lakshmi's lord. Krishna then meditated on Shiva in his heart, bowing and prostrate. He understood that Drona's weapon had done this to eliminate all the Pandavas. He had been given the extremely radiant Sudarshana discus to protect himself, and by Shiva's command used it to protect her. Since Ashvatthama was himself born of Shiva's portion, he understood that Krishna's conduct was due to his being Shiva's supreme devotee, and gradually changed his mind. Krishna was pleased and made all the Pandavas fall at the feet of the king of Shiva's devotees. Drona's son was pleased with Krishna and the Pandavas, showed them favour and lovingly gave them many boons. So the lord Maheshvara engages in many supreme plays. In the form of Drona's son he took an avatara on earth. Ashvatthama, Shiva's avatara, strong and valiant, brought happiness to the three worlds and is still there on the banks of the Jahnavi. Nandi said he had described lord Shankara's avatara as Ashvatthama, which gives every kind of success and grants devotees the desired fruits. A person who controls himself and devotedly reads or recites it gains the desired success and at the end goes to Shiva's city.
Retold in our own words from Bibek Debroy's English translation of the Shiva Purana (Penguin Classics). Names, numbers and the order of events follow the source.