I know that Lord Shiva tests his devotees' devotion towards him, but I would like to know the references in any Hindu texts that confirm this.
2 Answers
Yes, there are various events in our scriptures. But it doesn't mean that Lord Shiva will test for each and every devotee necessarily.
1) Testing of Upamanyu:
One of the popular events is when Lord Shiva took the form of Lord Indra and tested Upamanyu. That form of Lord Shiva is known as Sureshwara. Mahabharata in this chapter describes the event:
In this way, I adored Mahadeva for a full thousand years of the celestials. After this, the puissant Mahadeva, the Master of all the universe, became gratified with me. Desirous of ascertaining whether I was solely devoted to him and him alone, he appeared before me in the form of Sakra (Indra) surrounded by all the deities. As the celebrated Sakra, he had a thousand eyes on his person and was armed with the thunderbolt. And he rode on an elephant whose complexion was of the purest white, with eyes red, ears folded, the temporal juice trickling down his cheeks, with trunk contracted, terrible to look at, and endued with four tusks.
Lord Shiva (in the form of Indra) then tells Upamanyu as:
Addressing me, he said,--O foremost of regenerate persons, I have been gratified with thee. Beg of me whatever boon thou desirest,--Hearing these words of Sakra I did not become glad. Verily, O Krishna, I answered the chief of the celestials in these words.--I do not desire any boon at thy hands, or from the hands of any other deity. O amiable deity, I tell thee truly, that it is Mahadeva only from whom I have boons to ask. True, true it is, O Sakra, true are these words that I say unto thee. No other words are at all agreeable to me save those which relate to Maheswara....
Finally being satisfied with answers given by Upamanyu, Lord Shiva shows up in magnificent form:
Having said these words unto the chief of the celestials, I became overwhelmed with grief at the thought of Mahadeva not having been gratified with me not withstanding my severe austerities. Within the twinkling of an eye, however, I saw the celestial elephant I had beheld before me transformed into a bull as white as a swan, or the Jasminum pubescens, or a stalk of the lotus or silver, or the ocean of milk. Of huge body, the hair of its tail was black and the hue of its eyes was tawny like that of honey. Its horns were hard as adamant and had the colour of gold. With their very sharp ends, whose hue was a mild red, the bull seemed to tear the Earth. The animal was adorned all over with ornaments made of the purest gold. Its face and hoofs and nose and ears were exceedingly beautiful and its waist too exceedingly well-formed. Its flanks were possessed of great beauty and its neck was very thick. Its whole form was exceedingly agreeable and beautiful to look at. Its hump shone with great beauty and seemed to occupy the whole of its shoulder-joint. And it looked like the summit of a mountain of snow or like a cliff of white clouds in the sky. Upon the back of that animal I beheld seated the illustrious Mahadeva with his spouse Uma.
SatRudra Samhita chapter 32 of the Shiva Purana also describes this story on how Lord Shiva took form of Indra and tested Upamanu:
एतस्मिन्नन्तरे शंभुर्विष्ण्वाद्यैः प्रार्थितः प्रभुः ।। परीक्षितुं च तद्भक्तिं शक्ररूपोऽभवत्तदा।।१९।। शिवा शचीस्वरूपाभूद्गणाः सर्वेऽभवन्सुराः।। ऐरावतगजो नन्दी सर्वमेव च तन्मयम् ।।3.32.२०।।। ततः साम्बः शिवः शक्रस्वरूपस्सगणो द्रुतम्।। जगामानुग्रहं कर्तुमुपमन्योस्तदाश्रमम् ।। परीक्षितुं च तद्भक्तिं शक्ररूपधरो हरः ।। प्राह गंभीरया वाचा बालकन्तं मुनीश्वर ।। २२।।
In the meantime, requested by Vishnu and others, Shiva assumed the form of Indra in order to test his devotion. Parvati took the form of Sachi. The Ganas became the gods, Nandin became the elephant Airavata. Everything belonging to Shiva became that of Indra. Then Shiva accompanied by Parvati and the Ganas, and assuming the form of Indra went to the hermitage of Upamanyu in order to bless him. O great sage, in order to test his devotion, Siva in the form of Indra, spoke to the boy in a grave tone.
2) Testing of Parvati:
Parvati is always present as the left part in the body of Shiva, though while in her form as the daughter of mountains she did a severe penance using Panchakshari mantra taking initiation from Narada Rishi. Lord Shiva first sends Saptarishis to test the devotion of Parvati and when they return Lord Shiva himself goes to Parvati taking the form of Jatila and begins to criticize Shiva. Rudra Samhita chapter 26 and chapter 27 of Shiva Purana deals with this story:
गतेषु तेषु मुनिषु स्वं लोकं शंकरः स्वयम् ।। परीक्षितुं तपो देव्या ऐच्छत्सूतिकरः प्रभुः ।।१।। परीक्षा छद्मना शंभुर्द्रष्टुं तां तुष्टमानसः।। जाटिलं रूपमास्थाय स ययौ पार्वतीवनम् ।। २ ।। अतीव स्थविरो विप्रदेहधारी स्वतेजसा ।। प्रज्वलन्मनसा हृष्टो दंडी छत्री बभूव सः ।। ३ ।।
When those sages returned to their abodes, lord Shiva, the cause of great enjoyment and protection wanted to test the penance of the goddess. Under the pretext of testing, Shiva wanted to see her. With a delighted mind He assumed the form of a Jatila (an ascetic with matted hair) and went to the forest of penance of Parvati. He took the form of a very old man with the body of a brahmin. His brilliance shone. He was delighted in mind. He had an umbrella and a staff.
He begins to heavily criticise Lord Shiva and starts saying things like:
तन्मध्ये हि विरूपाक्षे एकोपि न गुणः स्मृतः ।। ३२ ।। तवापि कामो दयितो दग्धस्तेन हरेण च ।। अनादरस्तदा दृष्टो हित्वा त्वामन्यतो गतः ।।३३।। जातिर्न दृश्यते तस्य विद्याज्ञानं तथैव च ।। सहायाश्च पिशाचा हि विषं कण्ठे हि दृश्यते ।। ३४ ।। एकाकी च सदा नित्यं विरागी च विशेषतः ।। तस्मात्त्वं हि हरे नैव मनो योक्तुं तु चार्हसि ।। ३५ ।। क्व च हारस्त्वदीयो वै क्व च तन्मुण्डमालिका ।। अंगरागः क्व ते दिव्यः चिताभस्म क्व तत्तनौ ।। ३६ ।। सर्वं विरुद्धं रूपादि तव देवि हरस्य च ।। मह्यं न रोचते ह्येतद्यदिच्छसि तथा कुरु ।।३७।। असद्वस्तु च यत्किंचित् तत्सर्वं स्वयमीहसे ।। निर्वर्तय मनस्तस्मान्नोचेदिच्छसि तत्कुरु ।। ३८ ।।
There is not even a single quality in the odd-eyed Siva out of the innumberable qualities pleasing to women and expected in bride-grooms.Your friend Kama was burnt by Shiva. He insulted you also by leaving you off and going elsewhere. His caste is not recognised. He has no learning or wisdom. His assistants are the ghosts. Poison is seen even in His throat. He also moves about in isolation. He is detached from everything particularly. Hence you cannot fix your mind in Him. Where your necklace and where the garland of skulls that he wears? Where your rich divine unguent and where the ash from the funeral pyre that He has on His body? O divine lady, everything concerning you and Siva, such as form, features etc. is mutually discordant. I do not like your resolution. You can do whatever you please.You yourself have evolved taste for all bad objects. Turn your mind from Him. If not, do whatever you please.
Lord Shiva then finally shows his true form to Devi Parvati:
इत्युक्त्वा चोमया यावत्पादमुत्क्षिप्यते मुने ।। असौ तावच्छिवस्साक्षादालंबे प्रियया स्वयम् ।। ४१ ।। कृत्वा स्वरूपं सुभगं शिवाध्यानं यथा तथा ।। दर्शयित्वा शिवायै तामुवाचावाङ्मुखीं शिवः ।।४२।। शिव उवाच ।। कुत्र यास्यसि मां हित्वा न त्वं त्याज्या मया पुनः ।। प्रसन्नोऽस्मि वरं ब्रूहि नादेयम्विद्यते तव ।। ।। ४३ ।। अद्यप्रभृति ते दासस्तपोभिः क्रीत एव ते ।। क्रीतोऽस्मि तवसौन्दर्यात्क्षणमेकं युगाय ते ।। ४४ ।। त्यज्यतां च त्वया लज्जा मम पत्नी सनातनी ।। गिरिजे त्वं हि सद्बुध्या विचारय महेश्वरि ।। ४५ ।। मया परीक्षितासि त्वं बहुधा दृढमानसे ।। तत्क्षमस्वापराधम्मे लोकलीलानुसारिणः ।। ४६ ।। न त्वादृशीम्प्रणयिनीं पश्यामि च त्रिलोकके ।। सर्वथाहं तवाधीनस्स्वकामः पूर्य्यतां शिवे ।। ४७ ।।
Saying this, O sage, even as Parvati was about to step ahead, the brahmin manifesting as Shiva clasped his beloved. After assuming the handsome form in the manner Parvati had meditated upon and manifesting it to Parvati, Shiva addressed her while she stood with her lowered head. Shiva said:-- "Where will you go, leaving me? You are not to be discarded again by me. I am delighted. Tell me what boon shall I grant you. There is nothing that cannot be given to you. From today I am your slave bought by you by performing penance. I have been bought by your beauty. Even a moment appears like a Yuga. O Parvati, O great Goddess, you are my eternal wife. Let this shyness be eschewed. You please ponder with your keen intellect. O steady-minded one, you have been tested by me in various ways. Let my guilt be excused in following this worldly game. Even in the three worlds I do not see a beloved like you. O Parvati, in every respect I am subservient to you. You can fulfil all your desires.
3) Testing of Arjuna:
This chapter of Mahabharata describes how Lord Shiva tested Arjuna by taking a form of Kirata and also fought with him for sometime:
Vaisampayana said, "After all those illustrious ascetics had gone away, that wielder of the Pinaka and cleanser of all sins--the illustrious Hara--assuming the form of a Kirata resplendent as a golden tree, and with a huge and stalwart form like a second Meru, and taking up a hand some bow and a number of arrows resembling snakes of virulent poison, and looking like an embodiment of fire, came quickly down on the breast of Himavat. And the handsome god of gods was accompanied by Uma in the guise of a Kirata woman, and also by a swarm of merry spirits of various forms and attire, and by thousands of women in the form and attire of Kiratas. And, O king, that region suddenly blazed up in beauty, in consequence of the arrival of the god of gods in such company. And soon enough a solemn stillness pervaded the place. The sounds of springs, and water-courses, and of birds suddenly ceased. And as the god of gods approached Pritha's son of blameless deeds, he beheld a wonderful sight, even that of a Danava named Muka, seeking, in the form of a boar, to slay Arjuna.
Kirata form of Lord Shiva and Arjuna heavily fight for some time:
The illustrious god in the form of the huge-bodied Kirata, however, bore that shower of trees and rocks with patience. The mighty son of Pritha then, his mouth smoking with wrath, struck the invincible god in the form of a Kirata, with hi clenched fists, blows that descended like thunderbolts. The god in the Kirata form returned Phalguna's blows with fierce blows resembling the thunderbolts of Indra. And in consequence of that conflict of blows between the son of Pandu and the Kirata, there arose in that place loud and frightful sounds. That terrible conflict of blows, resembling the conflict of yore between Vritra and Vasava, lasted but for a moment.
Arjuna recognizes that the Kirata is Lord Shiva himself after this incident:
And struck by the illustrious god, he became breathless and, falling down on earth without power of moving, looked like one that was dead. Soon, however, he regained consciousness, and, rising from his prostrate position, with body covered with blood, became filled with grief. Mentally prostrating himself before the gracious god of gods, and making a clay image of that deity, he worshipped it, with offerings of floral garlands. Beholding, however, the garland that he had offered to the clay image of Bhava, decking the crown of the Kirata, that best of Pandu's sons became filled with joy and regained his ease. And he prostrated himself thereupon at the feet of Bhava, and the god also was pleased with him.
Then Lord Shiva gives him darshana in his real form:
Vaisampayana continued, "Phalguna then beheld him--Mahadeva--that god of blazing splendour-that wielder of the Pinaka-that one who had his abode on the mountains (of Kailasa)--accompanied by Uma. Bending down on his knee and bowing with his head, that conqueror of hostile cities-the son of Pritha-worshipped Hara and inclined him to grace. And Arjuna said, 'O Kapardin, O chief of all gods, O destroyer of the eyes of Bhaga, O god of gods, O Mahadeva, O thou of blue throat, O thou of matted locks, I know thee as the Cause of all causes. O thou of three eyes, O lord of all!
This testing of Arjuna by taking form of Kirata is also described in Shiva Purana Shatrudra Samhita chapter 39:
विचार्य्येति च तत्रैव बाणं संस्थाय संस्थितः ।।२४।। एतस्मिन्नन्तरे तत्र रक्षार्थं ह्यर्जुनस्य वै ।। तद्भक्तेश्च परीक्षार्थं शंकरो भक्तवत्सलः।।२५।। विदग्धभिल्लरूपं हि गणैः सार्ध महाद्भुतम् ।। तस्य दैत्यस्य नाशार्थं द्रुतं कृत्वा समागतः ।। २६ ।।
In the meantime, Shiva, favourably disposed to his devotees, assumed the wonderful form of an efficient hunter and came there along with his Gaṇas in order to slay that Daitya, to protect Arjuna as well as to test his devotion. The hunter had tucked up his lion-cloth and folded up Shiva’s banner. His body was lined with the white ash. He held a bow and arrows.
There are many other stories like Lord Shiva taking the form of Yatinatha to test Bhilla couples, Lord Shiva hiding a lotus flower from Lord Vishnu, Lord Shiva taking the form of Yaksha to test gods, etc... I might add these stories later in this answer also. But for now, I think the above stories are sufficient!
Well, @Tezz has given most of the answer but I want to add some more to the list, say it as no. 4, 5, 6,7,... And so on.
Testing of Brahma and Vishnu
Once Lord Brahma and Lord Vishnu faught for their supremacy but to stop them Lord Shiva became an infinite lingam and told Brahma to find it's top and Vishnu to find it's bottom. Lord brahma went upward as a swan and lord vishnu downward as a varaha. This linga bodhok katha, aka origin of Shivalingam is from Shiva Purana, Section 1 - Vidyeśvara-saṃhitā. Chapter 5-9.
- There in the battlefield Brahmā and Acyuta desirous of killing each other were awaiting the result of the Māheś-vara and the Paśupata weapons hurled by them.
10-11. The flames emitted by the two weapons of Brahmā and Viṣṇu burned the three worlds. On seeing this imminent untimely dissolution the bodiless form of Śiva assumed the terrific form of a huge column of fire in their midst.
The two weapons of fiery flame potential enough to destroy the entire world fell into the huge column of fire that manifested itself there instantaneously.
Seeing that auspicious wonderful phenomenon assuaging the weapons they asked each other “What is this wonderful form?”
“What is this column of fire that has risen up? It is beyond the range of senses. We have to find out its top and bottom.”
Jointly deciding like this, the two heroes proud of their prowess immediately set about assiduously in their quest.
16-18. “Nothing will turn up if we are together”. Saying this, Viṣṇu assumed the form of a Boar and went in search of the root. Brahmā in the form of a swan went up in search of the top. Piercing through the netherworlds and going very far below, Viṣṇu could not see the root of the fiery column. Utterly exhausted, Viṣṇu in the form of a Boar returned to the former battle-ground.
- Dear one, your father, Brahmā who went high up in the sky saw a certain bunch of Ketakī flower of mysterious nature falling from above.
20-21. On seeing the mutual fight of Brahmā and Viṣṇu, lord Śiva laughed. When his head shook, the Ketakī flower dropped down. Although it had been in its downward course for many years, neither its fragrance nor its lustre had been diminished even a bit. The flower had been intended to bless them.
22-23. (Brahmā said) “O lord of flowers, by whom had you been worn? Why do you fall? I have come here to seek out the top, in the form of a swan.” (The flower replied) “I am falling down from the middle of this primordial column that is inscrutable. It has taken me a long time. Hence I do not see how you can see the top.”
24-25. “Dear friend, hereafter you must do as I desire. In the presence of Viṣṇu you must say like this. O Acyuta, the top of the column has been seen by Brahmā. I am the witness for the same.” Saying this he bowed to the Ketakī flower again and again. Even falsehood is recommended in times of danger. So say the authoritative texts.
- (Returning to the original place) on seeing Viṣṇu there, utterly exhausted and lacking pleasure, Brahmā danced with joy. Viṣṇu, in the manner of a eunuch admitting his inability(to a woman), told him the truth (that he could not see the bottom). But Brahmā told Viṣṇu like this.
27-28. “O Hari, the top of this column has been seen by me. This Ketakī flower is my witness.” The Ketaka flower repeated the falsehood endorsing the words of Brahmā in his presence. Hari, taking it to be true, made obeisance to Brahmā. He worshipped Brahmā with all the sixteen means of service and homage.[1]
The Lord taking up a visible form in order to chastise Brahmā who practised trickery, came out of the column of fire. On seeing the lord, Viṣṇu stood up and with his hands shaking with fear caught hold of the lord’s feet.
It is out of ignorance and delusion about you whose body is without a beginning or an end that we indulged in this quest prompted by our own desire. Hence O, Sympathetic Being, forgive us for our fault. In fact, it is but another form of your divine sport.
Īśvara said:— 31. “O dear Hari, I am pleased with you, because you strictly adhered to truth in spite of your desire to be a lord. Hence among the general public you will have a footing equal to mine. You will be honoured too likewise.
Hereafter you will be separate from me having separate temple, installation of idols, festivals and worship.”
Thus, formerly, the lord was delighted by the truthfulness of Hari and offered him a footing equal to his own even as the assembly of the devas was witnessing the same.
So due to remain truthful Lord Vishnu gained an equal status to Lord Shiva and the duty of preservation and for lying Lord Brahma was cursed to remain un worshipped and his lying 5th head was chopped off by lord Kaal bhairava.
Nandikeśvara said:—
Mahādeva then created a wonderful person, Bhairava, from the middle of his brows to quell the pride of Brahmā.
This Bhairava knelt before the lord in the battle-field and said—“O lord, what shall I do? Please give me your directives quickly.”
“Dear, here is Brahmā, the first deity of the universe. Worship him with your sharp-pointed quick-moving sword.”
With one of his hands he caught hold of the tuft of Brahma’s fifth head that was guilty of haughtily uttering a falsehood, and with the hands he furiously shook his sword in order to cut it off.
Your father trembled like a plantain tree in a whirlwind, with his ornaments scattered here and there, his cloth ruffled and loosened, the garland displaced, the upper cloth hanging loose and the glossy tuft dishevelled, and fell at the feet of Bhairava.
But later on Lord Brahma was also forgiven by Lord Shiva and was given the duty of creation and made him the god of yagnas and havans.
Testing of Vishnu
During the gaining of Sudarshan chakra of Lord vishnu from Lord Shiva. Shiv Puran, Section 4 - Koṭirudra-Saṃhitā, chapter 34.
Vyāsa said:—
- O great sages, on hearing the words of Sūta the sages praised him and spoke desiring the welfare of the worlds.
The sages said:— 2. O Sūta, you know everything. Hence we ask you. O holy lord, please narrate the greatness of the phallic image Harīśvara.
- O dear, this was heard by us formerly that by propitiating Harīśvara, Viṣṇu acquired his discus Sudarśana. Please narrate that story particularly.
Sūta said:— 4. O great sages, may the auspicious story of Harīśvara be heard, how Sudarśana was acquired by Viṣṇu formerly from Śiva.
On a certain occasion the Daityas became very powerful. They harassed the worlds and violated sacred rites.
Tormented by the Daityas of great strength and exploit, the gods narrated their misery to Viṣṇu, their saviour.
The gods said:— 7. O lord, be merciful. We are very much afflicted by the Daityas. Where shall we go? What shall we do? We have resorted to you, for you are worthy of seeking refuge by us.
Sūta said:— 8. On hearing these words of the gods distressed in mind, Viṣṇu remembered the lotus-like feet of Śiva and said.
Viṣṇu said:— 9. O gods, I shall carry out your task after propitiating Śiva. These powerful enemies shall be conquered with great effort.
Sūta said:— 10. Thus consoled by lord Viṣṇu, the gods thought that the Daityas would be surely killed. They then went to their respective abodes.
For the victory of the gods, Viṣṇu worshipped śiva, the lord of all the gods, the imperishable and the cosmic witness of all.
He went to Kailāsa and dug a pit there wherein he kindled fire and performed penance.
He worshipped Śiva joyously with various mantras and hymns prescribed for the worship of earthen image.
O great sages, he worshipped with the lotus-flowers growing in the Mānasa lake. He sat firmly in the Yogic posture and did not move at all.
Thinking decisively—“By all means I shall stay here till the lord is pleased” Viṣṇu worshipped Śiva.
O brahmins, when Śiva was not pleased with Viṣṇu, the latter began to think anxiously.
After thinking thus he rendered him various services. Still, lord Śiva, indulging in divine sports was not satisfied.
Surprised much at this, Viṣṇu, endowed with great devotion, eulogised lord Śiva by reciting his thousand names with pleasure.
Repeating every name, he worshipped Śiva, favourably disposed towards those who seek refuge in him? with a lotus flower.
In order to test the piety of Viṣṇu, one of the thousand lotus-flowers was taken away by Śiva.
That wonderful Māyā of Śiva was not noticed by Viṣṇu. But when he came to know of the shortage he started to search.
In order to find it out he roamed over the world, steadily maintaining his sacred rite. But not finding the same, the pious Viṣṇu offered one of his eyes (instead of the lotus).
On seeing it Śiva who destroys all miseries was delighted and appeared before him. He spoke these words to Viṣṇu.
Śiva said:— 24. O Viṣṇu, I am delighted with you. Mention the boon you wish to have. I shall grant you what you desire. There is nothing which cannot be given to you.
Sūta said:— 25. On hearing the words of Śiva, Viṣṇu was pleased in his mind. Extremely delighted he spoke to Śiva with palms joined in reverence.
Viṣṇu said:— 26. What is there to be mentioned to you? You are the immanent soul. Still, O Lord, I mention the same with due deference to your behest.
O Sadāśiva, the entire universe is afflicted by the Daityas. We have no pleasure at all. Our weapons are in effectual in killing the Daityas.
What shall I do? Where shall I go? I have no greater saviour than you. O lord, I seek refuge in you.
Sūta said:— 29. After saying this he stood in affliction and bowed to Śiva, the supreme soul.
On hearing these words of Viṣṇu, Śiva, the lord of gods, gave him his discus Sudarśana shining with the mass of splendour.
On receiving it Viṣṇu slew the powerful demons immediately with the discus without any strain.
Thereupon the universe derived normalcy, the gods became happy. After receiving the Sudarśana missile Viṣṇu was greatly delighted.
The sages said:— 33. What is that hymn of Śiva that consists of his thousand names? What is that hymn whereby Śíva was so much delighted that he gave Viṣṇu the discus.
- Please expound the glory of this hymn to us and narrate the dialogue between Śiva and Viṣṇu. The merciful nature of Śiva towards Viṣṇu may also be narrated to us.
Vyāsa said:— 35. On hearing the words of the pious sages, Sūta spoke after remembering the lotus-like feet of Śiva.
Even Mahabharata says the same.
यत्र लेभे हरिश्चक्रमुपास्य बहुभिर्दिनैः | पुष्करैः शतपत्रैश्च नेत्रेण च जगत्पतिम् ||
That place where (Kailash) Hari (Vishnu) obtained the Chakra by worshiping for several days the Jagatpati (Shiva), by lotus flowers and by his eye.
~ Hari Vamsha Parva 3.84.11 (Mahabharata).
And,
The Mahabharata. Book 13: Anusasana Parva. SECTION XIV.:->
O Kesava, in days of yore, upon the body of that great cause of universal affliction. The discus which thou bearest, O sinless one, was given unto thee by Mahadeva after he had slain a Daitya that was proud of his strength and used to live within the waters (Jalandhara). That discus, blazing with energy and like unto fire, was created by the great god having for his device the bull. Wonderful and irresistible in energy it was given unto thee by that illustrious god. In consequence of its blazing energy it was incapable of being gazed at by any person save Siva the wielder of Pinaka. It was for this reason that Bhava (Siva) bestowed upon it the name of Sudarsana. From that time the name Sudarsana came to be current in all the worlds.
Sharabha Upanishad.:
Salutations to that Rudra whose feet were worshipped by the flower of Vishnu’s eyes and who being pleased gave him the holy wheel (Chakra). 7
Testing of Devtas
After Khseera sagara madanam, the Devas got Amrutam. The devas became very strong and easily defeated the Asuras. The Devas thought that it was their own strength which was responsible for the Victory over Asuras. They forgot altogether that it was only by the grace of Lord Shiva,the absolute brahman. The Devas started feeling very proud about their strength. They said to themselves :
"vijayo'smakamevayam mahimeti " ( ie., "Verily, this victory is ours; verily, this glory is ours only.")
Lord Shiva ,the omniscient, decided to teach the Devas a lesson. So he appeared before Devas in form of an Yaksha. The Gods decided to know about this new creature.
Lord Shiva In the form of Yaksheswara
te agnimabruvanjataveda etadvijanihi kimidam yakshamiti tatheti
The devas asked Agni Deva : "O Agni! Find out who this great Spirit is."
Agni deva :"Yes,"
tadabhyadravattamabhyavadatko'sityagnirva ahamasmityabravijjataveda va ahamasmiti
Lord Shiva who's in Yaksha form, asked him: "Who are you?"
Agni deva said : "I am known as Agni; I am also called Jataveda."
tasmimstvayi kim viryamityapidam sarvam daheyam yadidam prithivyamiti
Yaksha said: "What power is in you, who are so well known?"
Agni deva replied: "I can burn all— whatever there is on earth."
tasmai trinam nidadhavetaddaheti | tadupapreyaya sarvajavena tanna shashaka dagdhum sa tata eva nivavrite naitadashakam vijnatum yadetadyakshamiti
Iswara put a straw before him and said: "Burn this."
Agnideva rushed toward it with all his ardour but could not burn it. Then he returned from the Spirit and said to the gods: "I could not find out who this Spirit is,"
atha vayumabruvanvayavetadvijanihi kimetadyakshamiti tatheti
Then the devas said to Vayu : "O Vayu! Find out who this great Spirit is."
Vayu deva said : "Yes," , then he hastened to It.
tadabhyadravattamabhyavadatko'siti vayurva ahamasmityabravinmatarishva va ahamasmiti
Parameswara asked him: "Who are you?"
Vayu replied : "I am known as Vayu; I am also called Matarisva."
tasmimstvayi kim viryamityapidam sarvamadadiya yadidam prithivyamiti
Lord shiva said: "What power is in you, who are so well known?"
Vayu replied: "I can carry off all— whatever there is on earth."
tasmai trinam nidadhavetadadatsveti tadupapreyaya sarvajavena tanna shashakadatum sa tata eva nivavrite naitadashakam vijnatum yadetadyakshamiti
Brahman put a straw before him and said: "Carry this." He rushed toward it with all his ardour but could not move it. Then he returned from the Spirit and said to the gods: "I could not find out who this Spirit is,"
athendramabruvanmaghavannetadvijanihi kimetadyakshamiti tatheti tadabhyadravattasmattirodadhe
Then the gods said to Indra: "O Maghavan! Find out who this great Spirit is."
Indra said: "Yes," and hastened to It.
sa tasminnevakashe striyamajagama bahushobhamanamuma haimavatim tamhovaca kimetadyakshamiti
But the Lord shiva disappeared from him. Then Indra beheld in that very region of the sky a Woman highly adorned. She was Uma, the daughter of the Himalayas. In order to marry Lord shiva, she was doing severe penance. Uma knew the supreme nature of Lord Shiva.
Uma devi, The Daughter of Himalayas
Indra approached her and said: "Who is this great Spirit?"
sa brahmeti hovaca brahmano va etadvijaye mahiyadhvamiti tato haiva vidancakara brahmeti
tasmadva ete deva atitaramivanyandevanyadagnirvayurindraste hyenannedishtham pasparshuste hyenatprathamo vidancakara brahmeti
Parvati replied : "It is, indeed,Absolute Brahman Shiva . Through the victory of Brahman alone have you attained glory." Later, she taught Indra about the supreme nature of Lord Shiva. After that Indra understood that It was Brahman(Lord Shiva).
tasmadva indro'titaramivanyandevansa hyenannedishtham pasparsha sa hyenatprathamo vidancakara brahmeti
Since they approached very near in comprehending the Supreme nature of Lord Shiva and were the first to know that the Yaksha was Brahman(shiva) , these devas, namely, Agni, Vayu and Indra, excelled the other gods. And since Indra was the one got the knowledge of Brahman from maa uma he became the king of the devtas.
This story can be found in Kena Upanishad and Sri Shiva Maha Puranam. Prd..
There are many more stories like that but I think these are more than enough, just for now.
I hope this clarifies all your queries.