The Lord tells Moses to take vengeance on the Midianites, and afterward he will be gathered to his people. Moses orders a thousand men from each tribe, twelve thousand in all, to go to war. Phinehas, son of the priest Eleazar, goes with them with the vessels of the sanctuary and the trumpets. They fight against Midian as the Lord commanded and kill every male, among them five kings of Midian; they also kill Balaam, son of Beor, with the sword.
The Israelites take the women and children captive and carry off the spoil, and they burn the cities. Moses is angry with the officers because they let the women live, who on Balaam's advice made Israel sin at Peor. He orders the male children killed, along with the women who have lain with a man, but the young girls who are virgins are kept alive.
All who killed or touched the dead must stay outside the camp seven days and purify themselves on the third and seventh days. Eleazar also explains how to purify metals and objects with fire and the water of purification. Then Moses, Eleazar and the chiefs count the spoil and divide it in half between the fighters and the congregation; from the soldiers' half one five-hundredth is set apart for the Lord, and from the congregation's one fiftieth for the Levites.
The officers count their men and not one is missing, so they bring to the Lord the gold each had taken, as atonement for their lives and as a memorial before the Lord.