Dwarf spheroidal galaxies are the most dark matter dominated systems in the nearby Universe and their origin is one of the outstanding puzzles of how galaxies form. Dwarf spheroidals are poor in gas and stars, making them unusually faint, and those known as ultra-faint dwarfs have by far the lowest measured stellar content of any galaxy. Previous theories require that dwarf spheroidals orbit near giant galaxies like the Milky Way, but some dwarfs have been observed in the outskirts of the Local Group. Here we report simulations of encounters between dwarf disk galaxies and somewhat larger objects. We find that the encounters excite a process, which we term ``resonant stripping, that can transform them into dwarf spheroidals. This effect is distinct from other mechanisms proposed to form dwarf spheroidals, including mergers, galaxy-galaxy harassment, or tidal and ram pressure stripping, because it is driven by gravitational resonances. It may account for the observed properties of dwarf spheroidals in the Local Group, including their morphologies and kinematics. Resonant stripping predicts that dwarf spheroidals should form through encounters, leaving detectable long stellar streams and tails.