Blazar emission is dominated by non-thermal radiation from a relativistic jet pointing toward us, therefore undergoing Doppler beaming. This is responsible for flux enhancement and contraction of the variability time scales, so that most blazars appear as luminous sources characterized by noticeable and fast flux changes at all frequencies. The mechanisms producing their unpredictable variability are debated and include injection, acceleration and cooling of particles, with possible intervention of shock waves or turbulence. Changes in the viewing angle of the emitting knots or jet regions have also been suggested to explain flaring events or specific properties such as intraday variability, quasi-periodicities, or the delay of radio flux variations relative to optical changes. However, such a geometric interpretation has not been universally accepted because alternative explanations based on changes of physical conditions can also work in many cases. Here we report the results of optical-to-radio monitoring of the blazar CTA 102 by the Whole Earth Blazar Telescope Collaboration and show that the observed long-term flux and spectral variability is best explained by an inhomogeneous, curved jet that undergoes orientation changes. We propose that magnetohydrodynamic instabilities or rotation of a twisted jet cause different jet regions to change their orientation and hence their relative Doppler factors. In particular, the recent extreme optical outburst (six magnitudes) occurred when the corresponding jet emitting region acquired a minimum viewing angle.