"And God's anger was kindled because he was going, and the angel of the LORD stationed himself [in the road as an adversary (satan) against him]" (Numbers 22:22). He was an angel of mercy, but to Balaam he became an adversary (satan). And thus he said [to] Balaam: "You have caused me to perform a craft that is not my own," as it is stated: "Behold, I have come out as an adversary (satan)" (Numbers 22:32).
The Angel of Mercy Made an Adversary Against Balaam
Midrash Tanchuma Buber, Balak 11:6
ויחר אף אלהים כי הולך הוא ויתיצב מלאך ה' [בדרך לשטן לו] (שם שם כב), מלאך של רחמים היה ולו נעשה שטן, וכך אמר [אל] בלעם גרמת לי לשמש אומנות שאינה שלי, שנאמר הנה אנכי יצאתי לשטן (שם שם לב).