There was of course a fatal flaw in Balak's plan. (There's always a fatal flaw in the evil plans.. they're evil.) Rebbe Nachman teaches in Likkutei Moharan I:34 that HaShem brought Bnei Yisrael out of Egypt of His own desire, but once He gave Bnei Yisrael the Torah, they now can bend His Will, figguratively, to their own needs. This is because God's will is intimately bound up and clothed in the letters of the Torah. When Bnei Yisrael learns Torah and utters words of Torah in prayer, the more perfect their speech, the more they draw out HaShem's Will.
So it seems to me that Balak's plan might have worked, before Bnei Yisrael received the Torah, but since Bnei Yisrael received the Torah already, Bilaam really no longer had any power over them. Even in the moment of HaShem's anger, His Will would still be influenced by the Torah of Bnei Yisrael.
We can see how telling this is, by looking at the perush of the Ohr HaHayyim, (whose yahrtzeit it is today) who explained most if not all of the final blessing of (the three blessings of Bilaam for) Bnei Yisrael in relation to their Torah learning. He explains the four levels in Bnei Yisrael's commitment to Torah learning: 1) Those who travel itinerantly, like Shmuel HaNavi, amongst the people of Israel in order to teach them Torah. 2) Those who sit in the Temple and teach a very high level of Torah, who sit in an established place and let their Torah spread outward. 3) Those who each learn Torah in their own place, primarily for their own spiritual development. And lastly, 4) those who financially support the Torah study of others. R' Hayyim explains how each of the four praises of Bilaam's last berachah relate to one of the four types of engagement the Jews have with the Torah.
It is no wonder that R' Akiva relates that Torah is the source of a Jew's life, their very existence, in his parable about fish who cannot leave the water. [Berachot 61b]
An interesting side note is that I saw in shivchei Ohr HaHayyim that it is said he was a gilgul of the RaMaK, who was in turn a gilgul of R'Akiva. [Since these are not simple matters, and the technical complexity of them dwarfs many complex scientific systems, I wouldn't delve too deeply into this statement.]
[But why did all this take place? Not only to teach us that HaShem's plans are one step ahead of the evil doers. Rather to teach us that HaShem's plans totally transcend those of all the evil in the world: The real reason why this is in the Torah and why this whole plan even took place (according to me, upon the basis of the teachings of the Talmud, Berachot 7b) is so that Balak could earn enough merit that Ruth should descend from him, that she might eventually convert to Judaism and give birth to David HaMelech's (the Moshiah) grandfather.]