The history of contact between the two was initially friendly. The Midianites show up in the story of Joseph, when his brothers sold him to Midianite traders. They preserved his life and in turn sold him in Egypt to Potiphar (Genesis 37:25–36).
Later, Moses found safe haven among the Midianites when he fled from Pharaoh after killing an Egyptian. Moses’ own wife Zipporah was a daughter of the Midianite priest Jethro (Exodus 2:15–22). While he was in Midian, he received his call from the Lord (Exodus 3:1 – 4:23). After the exodus, Moses brought the entire nation of Israel to Midianite soil, Mount Sinai, where the Lord set Israel apart as his holy nation, and revealed his will (Exodus 19—Numbers 7).
Once Israel left Sinai, however, the relationship took a turn. The Midianites joined with Balak and the Moabites in trying to curse and destroy the Israelites (Numbers 22:1–6). Later the Midianites attempted to lead Israel away from the Lord through idolatry and fornication (Numbers 25:6–18). From that point on, the Lord forbade Israel from having contact with Midian. In fact, Israel eventually launched a full-scale war against Midian (Numbers 31:1–54). Now, some two hundred years later, the Midianites sought revenge.
1 The people of Israel did what was evil in the sight of the LORD, and the LORD gave them into the hand of Midian seven years.