Second-harmonic generation is of paramount importance in several fields of science and technology, including frequency conversion, self-referencing of frequency combs, nonlinear spectroscopy and pulse characterization. Advanced functionalities are enabled by modulation of the harmonic generation efficiency, which can be achieved with electrical or all-optical triggers. Electrical control of the harmonic generation efficiency offers large modulation depth at the cost of low switching speed, by contrast to all-optical nonlinear devices, which provide high speed and low modulation depth. Here we demonstrate all-optical modulation of second-harmonic generation in MoS2 with a modulation depth of close to 100% and speed limited only by the fundamental pulse duration. This result arises from a combination of D3h crystal symmetry and the deep subwavelength thickness of the sample, it can therefore be extended to the whole family of transition metal dichalcogenides to provide great flexibility in the design of advanced nonlinear optical devices such as high-speed integrated frequency converters, broadband autocorrelators for ultrashort pulse characterization, and tunable nanoscale holograms.