Herod the king, a ruler of man, did not want another ruler more respected than himself. He becomes troubled when he receives word that the prophecy of the Messiah may be fulfilled.
Now after Jesus was born in Bethlehem of Judea in the days of Herod the king, behold, wise men from the East came to Jerusalem, saying, “Where is He who has been born King of the Jews? For we have seen His star in the East and have come to worship Him.” When Herod the king heard this, he was troubled, and all Jerusalem with him. Matthew 2:1-3 NKJV
King Herod’s desire, his will, is now to destroy any chance of a new ruler to threaten his or his family’s reign. However, God’s will was unfolding on earth as it was written in prophecy. Herod has two plans to destroy the newborn king: 1) to have the wise men lead him to the newborn to kill him and, later when they do not comply, 2) to murder all male children two years of age and younger in the town of Bethlehem. Both plans are unsuccessful because the will of God is higher than man’s. Divine warnings were provided to both the wise men and Joseph.
Then, being divinely warned in a dream that they (the wise men) should not return to Herod, they departed for their own country another way. Matthew 2:12 NKJV
Now when they had departed, behold, an angel of the Lord appeared to Joseph in a dream, saying, “Arise, take the young Child and His mother, flee to Egypt, and stay there until I bring you word; for Herod will seek the young Child to destroy Him.” Matthew 2:13 NKJV