The sulfonamides (sulfas) are the oldest class of antibacterial drugs and inhibit the bacterial dihydropteroate synthase (DHPS, encoded byfolP), through chemical mimicry of its co-substratep-aminobenzoic acid (pABA). Resistance to sulfa drugs is mediated either by mutations infolPor acquisition ofsulgenes, which code for sulfa-insensitive, divergent DHPS enzymes. While the molecular basis of resistance throughfolPmutations is well understood, the mechanisms mediatingsul-based resistance have not been investigated in detail. Here, we determine crystal structures of the most common Sul enzyme types (Sul1, Sul2 and Sul3) in multiple ligand-bound states, revealing a substantial reorganization of theirpABA-interaction region relative to the corresponding region of DHPS. We use biochemical and biophysical assays, mutational analysis, and in trans complementation ofE. coliΔfolPto show that a Phe-Gly sequence enables the Sul enzymes to discriminate against sulfas while retainingpABA binding and is necessary for broad resistance to sulfonamides. Experimental evolution ofE. coliresults in a strain harboring a sulfa-resistant DHPS variant that carries a Phe-Gly insertion in its active site, recapitulating this molecular mechanism. We also show that Sul enzymes possess increased active site conformational dynamics relative to DHPS, which could contribute to substrate discrimination. Our results reveal the molecular foundation for Sul-mediated drug resistance and facilitate the potential development of new sulfas less prone to resistance.