Previously, Balak, king of the Moabites, a wicked people who are also referred to as Midianites had attempted to get Balaam to curse the Children of Israel. By the providence of God, that failed. God instructed Moses to prepare for battle against the Midianites. One thousand men from each of the twelve tribes were recruited and sent to war.
All of the men of Midian, including five kings and Balaam were killed. The women, children and all of their cattle and goods were captured and brought to the Israelite camp. Because the women with the counsel of Balaam had caused the Israelites to sin, Moses was displeased that they had saved them. He then had all of the male children and women except virgins killed.
Half of the spoils of war was given to those who fought and the other half went to the rest of the congregation. A portion of those spoils was given to the Lord as tribute.
A count of those who went into battle was taken and it was determined that not one man of them was missing. Were those twelve thousand men able to accomplish all that they did or did God deliver the Midianites into their hands? Go figure.