Balak, the king of Moav, was concerned about the Israelites' victories and asked the prophet Bilam to curse them. God told Bilam not to curse the blessed Israelites.
Despite Balak's offers of wealth, Bilam initially refused to act against God's command but eventually caved and set out to curse the Israelites.
An angel blocked their path when Bilam set out with Balak's officials. Bilam's donkey, seeing the angel, veered off the road after Billam, who was unable to see the angel yet, kept beating his donkey for not following his commands.
God allowed the donkey to speak to Bilam, who finally saw the angel. The angel questioned Bilam for beating the donkey, and Bilam admitted his error. Bilam offered to turn back if the angel disapproved, but the angel instructed him to continue with the men, speaking only what was directed.
Bilam and Balak traveled together, stopped to sacrifice, and took Balam to overlook the Israelites. Balaam built seven altars, offered sacrifices, and blessed the Israelites instead of cursing them.
Despite Balak's complaints, Bilam could only speak what God directed. Balak took Bilam to offer more sacrifices, but Balaam repeated blessings on the Israelites.
Enraged, Balak dismissed Bilam, who insisted on following God's command and continued to bless the Israelites.
While the Israelites stayed at Shittim, the people sinned with the Moabite women and worshiped their idol named Baal-peor. God instructed to impale the ringleaders; when one of the Israelites publicly brought a Midianite woman over to his companions, Pinchas, son of Eleazar, took a spear, followed the Israelite into the chamber, and stabbed the Israelite and the woman through the belly. Then, the plague against the Israelites ended, having killed 24,000.