In a rather enigmatic comment, Rashi writes, “evil, hatred, and vengeance were decided.” Haman must have known that all negative things were being focused in his direction.
The Brisker Rav asks how Haman knew that evil was decided. He answers that the Targum translates Achashverosh’s asking (Esther 7:5) “ay zeh” as “where is he.” In other words, the decision to punish whoever was responsible for this evil decree was final, and only required the finding of the culprit.
The Ben Ish Chai answers that Haman knew bad things were in store for him because he had already been advised by his friends (Esther 6:13) that his situation was deteriorating. Besides that, Haman thought that his situation would regress because Zeresh and his advisers thereby made what the Talmud (Kesubos 8b) calls “an opening for the Satan,” – saying something that could allow the Heavenly accuser an opportunity to punish someone.
The Dena Pishra answered that the verse, once again, used the word melech to refer to the King, H-Shem, because Haman angered Him, and now was certain the time had come for retribution.
Both the Dena Pishra and R’ Moshe David Valle note that the last letters of the phrase “ki chalasa eilav hara” (“because he saw that evil was decided on him”) spell out H-Sem’s Name in order. As the Chida and Rabbeinu Bachya write, when H-Shem’s Name is encoded in order, it represents His quality of mercy. This hints to the fact that Haman must have realized that all comes from H-Shem.
Parenthetically,this fact does not automatically define him as righteous righteous. After all, instead of getting on his knees at this point in true repentance to H-Shem, he begs for his life from an earthly queen. However, perhaps his begging Esther for his life instead of Achashverosh indicates that he acknowledges her righteousness, and its accompanying power. This very act may be the one that earned him the merit of having descendants who the Talmud (Sanhedrin 96b) says learn Torah in Bnei Brak learn Torah.