The Gemara in מסכת מכות teaches the idea that בדרך שאדם רוצה לילך בה מוליכין אותו, that a person will be led on the path that he wishes to take.
This is learned from Bilaam. Hashem told him not to go with Balak to curse the Jewish people, but he went anyways.
The תורה תמימה says that Hashem allowed Bilaam to go because of the principle, הכל בידי שמים חוץ מיראת שמים, that everything is from Heaven, except for fear of Heaven. Man has complete free will as to choose whether or not he will fear G-d.
What this means is that Hashem saw how badly Bilaam wanted to go, so He allowed it. Part of the way that Hashem runs the world, is that He allows a person to take the path that the person wants to take.
The only thing that went wrong in terms of Bilaam’s plan, was that Hashem allowed him to go, but He would not allow him to harm עם ישראל.
The bottom line is that we must never forget for a moment that it is Hashem that is running the world, and we are totally dependent upon Him.