The nation of Moav was terrified of the Jewish People after their conquest of the Emorites. Israel had shown itself to be an overwhelmingly powerful people, and was great in number. The Moabite king, Balak, sought out Bilaam, the prophet to the nations, to employ his power to curse the Jews.
Bilaam was a monotheist and a prophet, but was morally inferior to the monotheists like Malki Tzadek and Iyov who came before him. His spiritual aptitude to draw near to G-d is stunted by his egoism. He places himself at the service of earthly powers and potentates and their base desires. He thinks nothing of uprooting an entire nation without cause. This entire portion of Bilaam is written to reveal how G-d removed a spirit of holiness from the nations of the world because of the misuse of such spiritual gifts.
G-d instructs Bilaam not to go with Balak’s emissaries, warning him that he will not be able to accomplish his mission. You will not curse the (Jewish) people, for they are blessed! The element which makes this people a people is precisely the purpose which I have determined to promote with My sovereignty…Even the nations of the world conceive of this people as destined to be blessed!
If Bilaam had been a true prophet, he would have conveyed the same to Balak’s emissaries, and Moav and Midian, instead of fearing Israel’s conquering might, would have recognized the moral element which is the object of G-d’s blessing, and would have befriended Israel. Instead, Bilaam hints that G-d refuses to allow him to travel with the plebeians like them, instead of true princes. When Balak responds with a more impressive delegation, Bilaam hints again to this insatiable desire for money and honor.
When Bilaam’s greed and base desires so confused him, he lost his gift of intelligence and eloquence. Instead, G-d showed favor to his donkey’s intelligence, by granting it the gift of human speech. In doing so, He prepared Bilaam for what was to come. The human speech of Bilaam’s mouth would no longer be a product of his own will. The mouth that abused the gift would be placed in the service of Divine speech — against his will — to herald the Divine truth which he could not bear to utter at the expense of his greed. He Who gives speech to an animal can also put His Word in the mouth of Bilaam.
In his first attempt to curse Israel, Bilam proclaims: Can I curse what G-d has not cursed?! …Who would count the earthly element of Yaakov? Who would count the births among Israel as one would count the animal young? Here, he communicates to Balak that while the fortune of other nations may depend on their number of bodies, no so Israel. Balak was frightened by their numbers, but Bilaam adds insult to his injury. It is not their earthly element that determines their significance, and it is not their material conditions which lead to their success — even should you diminish their numbers, they will still prevail. To this, Bilaam adds a personal coda: I would like to die as they do — the death of the straight ones. Their death is more blessed than my own life, proclaims Bilaam, because they are straight. They measure up to the purpose for which humans were created. In his first blessing of the people he sought to curse, he recognizes at once that his misuse of Divine gifts of speech and intelligence resulted in his inability to use those gifts freely, and that the eternal blessing of the Jewish People stems from the exalted use of those Divine gifts, in moral freedom.
Sources: Commentary, Bamidbar 22:28; 23:10