The story behind this is that on one occasion, Pharaoh initiated a huge carnival and gathered all of the magicians of his kingdom in order to defeat Sayyiduna Musa عليه السلام. In the midst of this carnival which was crowded with hundreds and thousands of people, at one side stood a large number of magicians holding their magic devices in their hands and on the other side, there stood Sayyiduna Musa عليه السلام all alone yet determined against all of them. The magicians swore by the grace of pharaoh and threw their sticks and ropes onto the ground. Suddenly, those sticks and ropes became hissing snakes slithering all over the field. The whole crowd lost senses out of fear and a stampede broke out. Pharaoh and all of his magicians swelled with arrogance upon demonstrating their show and began to clap arrogantly considering it their victory.
Meanwhile, upon receiving the command of Allah عزوجل, Sayyiduna Musa عليه السلام placed his holy staff among the snakes. The blessed staff turned into a big and horrifying serpent that swallowed all of the snakes of the magicians. Upon witnessing this miracle, all of the magicians admitted their defeat and fell prostrate while proclaiming (اٰمَنَا بِرَبِ ھَارُونَ و مُوسیٰ) i.e. ‘We believe in Him Who is the Lord of Haroon and Musa’. Therefore, while mentioning this incident, the Holy Quran says:
They said, ‘O Musa, either you throw first – or shall we throw first?’ He said, ‘Rather, you may throw’; there upon their ropes and their sticks, by the strength of their magic, appeared to him as if they were fast running. And Musa sensed fear in his heart. We said, ‘Do not fear – it is you who is dominant.’ And cast down what is in your right hand – it will swallow their fabrications; what they have made is the trick of the magician; and a magician does not prosper, anywhere he comes.’ Therefore all the magicians were put down to prostrate – they said, ‘We believe in Him Who is the Lord of Haroon and Musa.’
[Kanz-ul-Iman (Translation of Quran)] (Part 16, Surah Taahaa, verse 65-70)