Heavy impurity ions can be removed from the toroidal magnetic trap in the helical magnetic field of a conventional torsatron or heliotron with the use of an alternating current (ac) electric field. The passing particles can be transformed into helically trapped ones and escape from the magnetic confinement volume by the drift of the particles in the inhomogeneous magnetic field. The frequency of the ac electric field is taken close to the bounce frequency in the helical magnetic field. The analysis is carried out on the basis of guiding center equations.