Joshua 23 - Judges 1
At the end of Joshua’s life he calls together the elders of Israel, and challenges them to a commitment of serving Jahweh, and refusing to serve the idols of Egypt, or of the remaining pagans living in their land. The people swear to serve the Lord, but over time that commitment fades, as those elders in Israel died off.
After Joshua died, the tribes of Judah (under Caleb’s leadership) joined with Simeon and did a good job of driving out the Canaanites and Perizzites from most of their inherited territory. The remaining tribes were not so diligent in doing that same thing, and they left many of the pagans living among them.