Before you consider any kind of medication, siphon out as many as you can. You won't get all of them, but you can get a lot of them.
If I understand correctly it's not the flatworm exit that causes problems, it's the toxins that the death of so many flatworms dying at once produces. So any means of reducing the numbers before you kill them is good.