Regarding the laser-driven acceleration of charged particles in photonic systems, a central unmet challenge is the achievement of simultaneous transverse and longitudinal stability at nonultrarelativistic energies. At such energies, Earnshaw’s theorem [S. Earnshaw, Trans. Cambridge Philos. Soc. 7, 97 (1842)] indicates that a synchronous accelerating wave gives a defocusing effect. We present a scheme in which particles are accelerated by interaction with a resonant spatial harmonic and are focused by strong ponderomotive interaction with nonresonant spatial harmonics. We show that this scheme exhibits net transverse focusing and longitudinal stability, and we discuss its use in a compact laser accelerator.