  We perform a multi-wavelength polarimetric study of the quasar CTA 102 during
an extraordinarily bright $\gamma$-ray outburst detected by the {\it Fermi}
Large Area Telescope in September-October 2012 when the source reached a flux
of F$_{>100~\mathrm{MeV}} =5.2\pm0.4\times10^{-6}$ photons cm$^{-2}$ s$^{-1}$.
At the same time the source displayed an unprecedented optical and NIR
outburst. We study the evolution of the parsec scale jet with ultra-high
angular resolution through a sequence of 80 total and polarized intensity Very
Long Baseline Array images at 43 GHz, covering the observing period from June
2007 to June 2014. We find that the $\gamma$-ray outburst is coincident with
flares at all the other frequencies and is related to the passage of a new
superluminal knot through the radio core. The powerful $\gamma$-ray emission is
associated with a change in direction of the jet, which became oriented more
closely to our line of sight ($\theta\sim$1.2$^{\circ}$) during the ejection of
the knot and the $\gamma$-ray outburst. During the flare, the optical polarized
emission displays intra-day variability and a clear clockwise rotation of
EVPAs, which we associate with the path followed by the knot as it moves along
helical magnetic field lines, although a random walk of the EVPA caused by a
turbulent magnetic field cannot be ruled out. We locate the $\gamma$-ray
outburst a short distance downstream of the radio core, parsecs from the black
hole. This suggests that synchrotron self-Compton scattering of near-infrared
to ultraviolet photons is the probable mechanism for the $\gamma$-ray
production.
