The evil sorcerer, Bilam, tried his utmost to destroy Israel with curses, but Hashem foiled his plans, and so twisted his tongue that his words came out as blessings rather than curses.
Seeing that his efforts were fruitless, Bilam resorted to another maneuver. Knowing that Hashem despises debauchery, he arranged that the Midianites seduce the Israelites to commit harlotry. This indeed angered Hashem, and twenty-four thousand Israelites died in a plague.
Bilam was a bitter enemy, but he could not harm Israel. However, when the Israelites surrendered to licentiousness, they became their own worst enemy.
We can defend ourselves against external enemies, but we are vulnerable to harm ourselves by inappropriate sexual behavior.