Numbers 22:21–38
When he arose in the morning, Balaam saddled his ass and departed with the Moabite dignitaries. But God was incensed at his going; so an angel of the Lord placed himself in his way as an adversary.
He was riding on his she-ass, with his two servants alongside, when the ass caught sight of the angel of the Lord standing in the way, with his drawn sword in his hand. The ass swerved from the road and went into the fields; and Balaam beat the ass to turn her back onto the road. The angel of the Lord then stationed himself in a lane between the vineyards, with a fence on either side. The ass, seeing the angel of the Lord, pressed herself against the wall and squeezed Balaam's foot against the wall; so he beat her again. Once more the angel of the Lord moved forward and stationed himself on a spot so narrow that there was no room to swerve right or left. When the ass now saw the angel of the Lord, she lay down under Balaam; and Balaam was furious and beat the ass with his stick.
Then the Lord opened the ass's mouth, and she said to Balaam, "What have I done to you that you have beaten me these three times?" Balaam said to the ass, "You have made a mockery of me! If I had a sword with me, I'd kill you." The ass said to Balaam, "Look, I am the ass that you have been riding all along until this day! Have I been in the habit of doing thus to you?" And he answered, "No."
Then the Lord uncovered Balaam's eyes, and he saw the angel of the Lord standing in the way, his drawn sword in his hand; thereupon he bowed right down to the ground. The angel of the Lord said to him, "Why have you beaten your ass these three times? It is I who came out as an adversary, for the errand is obnoxious to me. And when the ass saw me, she shied away because of me those three times. If she had not shied away from me, you are the one I should have killed, while sparing her." Balaam said to the angel of the Lord, "I erred because I did not know that you were standing in my way. If you still disapprove, I will turn back." But the angel of the Lord said to Balaam, "Go with the men. But you must say nothing except what I tell you." So Balaam went on with Balak's dignitaries.
When Balak heard that Balaam was coming, he went out to meet him at Ir-moab, which is on the Arnon border, at its farthest point. Balak said to Balaam, "When I first sent to invite you, why didn't you come to me? Am I really unable to reward you?" But Balaam said to Balak, "And now that I have come to you, have I the power to speak freely? I can utter only the word that God puts into my mouth."