Bacteria swim by rotating rigid helical flagella and periodically reorienting to follow environmental cues(1,2). Despite the crucial role of reorientations, their underlying mechanism has remained unknown for most uni-flagellated bacteria(3,4). Here, we report that uni-flagellated bacteria turn by exploiting a finely tuned buckling instability of their hook, the 100-nm-long structure at the base of their flagellar filament(5). Combining high-speed video microscopy and mechanical stability theory, we demonstrate that reorientations occur 10 ms after the onset of forward swimming, when the hook undergoes compression, and that the associated hydrodynamic load triggers the buckling of the hook. Reducing the load on the hook below the buckling threshold by decreasing the swimming speed results in the suppression of reorientations, consistent with the critical nature of buckling. The mechanism of turning by buckling represents one of the smallest examples in nature of a biological function stemming from controlled mechanical failure(6) and reveals a new role for flexibility in biological materials, which may inspire new microrobotic solutions in medicine and engineering(7).