Relativistic electron bunches used to produce synchrotron radiation are systematically subjected to spontaneous appearance of microstructures, when a high number of electrons are used. In storage rings, this usually leads to an intense coherent emission in the terahetz range, with powers that are orders of magnitude higher than standard incoherent emission. However this emission generally displays an erratic behavior, which has strongly limited its domain of application so far. In this Letter-inspired by the process of gain switching in lasers-we present a new method for controlling the electron bunch dynamics during this instability. We show that it is possible to trigger the formation of the microstructures in the bunch, and also to considerably enhance the peak power of the coherent terahertz bursts. The experimental demonstration of this scheme-based on the modulation of a rf-cavity signal-is performed at the SOLEIL facility.