The phrase "these things" refers to sending armies to attack them. Alternate translation: "done all these things to harm us" or "sent foreign armies to attack us" (See: [[rc://en/ta/man/jit/figs-explicit]])
Here "served foreign gods" represents worshiping foreign gods. God would punish them for serving foreign gods by making them serve foreign people. Alternate translation: "Because you ... worshiped foreign gods in your land, you will have to serve foreigners" (See: [[rc://en/ta/man/jit/figs-metaphor]])