The Midian War documented in the Hebrew Bible, Book of Numbers 31, was intended to exterminate the Midianites, who had "led the people of Israel to sin against God". (However, some Midianites survived well into the days of the Book of Judges.) Moses commanded one thousand males from each of the twelve tribes of Israel to destroy the cities and the warriors of Midian. The "false prophet" Balaam was killed, along with the five Midianite kings.
Only the Midianite women and children were left alive, but Moses was still not satisfied. Because they had "caused the children of Israel, through the counsel of Balaam," to sin against the Lord and had sent a plague into the congregation of Israelites, Moses decreed that every male child and nonvirginal woman be killed. The Midianite virgins were given to the Israelite soldiers as part of the spoils of war. The Israelites that participated in this killing had to stay outside the camp for seven days of ritual purification beforehand, presumably absolving them of the sin of murder.
According to the high priest Eleazar, the Lord instructed Moses to divide the spoils of war equally between the warriors and the entire congregation of Israelites. After this division was made, the military officers offered thousands of shekels worth of jewelry to the Lord as an atonement for their killing of the Midianites.