The effect of magnetic perturbations (MPs) on the helical self-organization of shaped tokamak plasmas is discussed in the framework of the nonlinear 3D MHD model. Numerical simulations performed in toroidal geometry with the textsc{pixie3d} code [L. Chacon, Phys. Plasmas {bf 15}, 056103 (2008)] show that $n=1$ MPs significantly affect the spontaneous quasi-periodic sawtoothing activity of such plasmas. In particular, the mitigation of sawtooth oscillations is induced by $m/n=1/1$ and $2/1$ MPs. These numerical findings provide a confirmation of previous circular tokamak simulations, and are in agreement with tokamak experiments in the RFX-mod and DIII-D devices. Sawtooth mitigation via MPs has also been observed in reversed-field pinch simulations and experiments. The effect of MPs on the stochastization of the edge magnetic field is also discussed.