When the Israelites were camped at Acacia Valley, the men began to have sexual intercourse with the Moabite women who were there.
These women invited them to sacrificial feasts, where the god of Moab was worshiped. The Israelites ate the food and worshiped the god
Baal of Peor. So the Lord was angry with them
and said to Moses, "Take all the leaders of Israel and, in obedience to me, execute them in broad daylight, and then I will no longer be angry with the people."
References for Numbers 25:4
Moses said to the officials, "Each of you is to kill every man in your tribe who has become a worshiper of Baal of Peor."
One of the Israelites took a Midianite woman into his tent in the sight of Moses and the whole community, while they were mourning at the entrance of the Tent of the Lord's presence.
When Phinehas, the son of Eleazar and grandson of Aaron the priest, saw this, he got up and left the assembly. He took a spear,
followed the man and the woman into the tent, and drove the spear through both of them. In this way the epidemic that was destroying Israel was stopped,
but it had already killed twenty-four thousand people.
The Lord said to Moses,
"Because of what Phinehas has done, I am no longer angry with the people of Israel. He refused to tolerate the worship of any god but me, and that is why I did not destroy them in my anger.
So tell him that I am making a covenant with him that is valid for all time to come.
He and his descendants are permanently established as priests, because he did not tolerate any rivals to me and brought about forgiveness for the people's sin."
The name of the Israelite who was killed with the Midianite woman was Zimri son of Salu, the head of a family in the tribe of Simeon.
The woman's name was Cozbi. Zur, her father, was chief of a group of Midianite clans.
The Lord commanded Moses,
"Attack the Midianites and destroy them,
because of the evil they did to you when they deceived you at Peor, and because of Cozbi, who was killed at the time of the epidemic at Peor."