While Israel was camped at Shittim (Acacia Grove), the men began to have sex with the Moabite women.
It started when the women invited the men to their sex-and-religion worship. They ate together and then worshiped their gods.
Israel ended up joining in the worship of the Baal of Peor. God was furious, his anger blazing out against Israel.
God said to Moses, "Take all the leaders of Israel and kill them by hanging, leaving them publicly exposed in order to turn God's anger away from Israel."
Moses issued orders to the judges of Israel: "Each of you must execute the men under your jurisdiction who joined in the worship of Baal Peor."
Just then, while everyone was weeping in penitence at the entrance of the Tent of Meeting, an Israelite man, flaunting his behavior in front of Moses and the whole assembly, paraded a Midianite woman into his family tent.
Phinehas son of Eleazar, the son of Aaron the priest, saw what he was doing, grabbed his spear,
and followed them into the tent. With one thrust he drove the spear through the two of them, the man of Israel and the woman, right through their private parts. That stopped the plague from continuing among the People of Israel.
But 24,000 had already died.
God spoke to Moses:
"Phinehas son of Eleazar, son of Aaron the priest, has stopped my anger against the People of Israel. Because he was as zealous for my honor as I myself am, I didn't kill all the People of Israel in my zeal.
So tell him that I am making a Covenant-of-Peace with him.
He and his descendants are joined in a covenant of eternal priesthood, because he was zealous for his God and made atonement for the People of Israel."
The name of the man of Israel who was killed with the Midianite woman was Zimri son of Salu, the head of the Simeonite family.
And the name of the Midianite woman who was killed was Cozbi daughter of Zur, a tribal chief of a Midianite family.
God spoke to Moses:
"From here on make the Midianites your enemies. Fight them tooth and nail.
They turned out to be your enemies when they seduced you in the business of Peor and that woman Cozbi, daughter of a Midianite leader, the woman who was killed at the time of the plague in the matter of Peor."