Aims. On the basis of the first 20 months of Fermi-LAT data and optical monitoring, the quasar 3C 345 has been identified as a γ-ray emitter. We investigate whether there is a connection between the γ-ray and optical variability of 3C 345 and the properties of its parsec-scale radio emission. Methods. We combined the Fermi-LAT data of 3C 345, covering an energy range of 0.1-300 GeV, with 32 Very Long Baseline Array observations of the object made at 43.2 GHz in the period of January 2008-March 2010.Results. The VLBA data reveal the morphology and kinematics of the flow on scales of up to ≈5 milliarcseconds (deprojected linear distances of 380 parsecs). The brightness temperature, T b (r), measured along the jet first decreases with distance ∝r −(0.95 ± 0.69) and later exhibits a break at ≈0.3 milliarcseconds (mas), with T b (r) ∝ r −(4.11 ± 0.85) at larger separations. Variations in the γ-ray, optical, and parsec-scale radio emission display a similar long-term trend that persists during the entire VLBA monitoring period. The γ-ray and optical variations on shorter timescales are related to structural changes in the jet on scales of ≈0.3 mas (≈23 parsecs, deprojected), with the γ-ray and optical flares possibly being related to the evolution of four distinct superluminal components identified in the flow. Conclusions. The observations indicate that both the quiescent and flaring components of the γ-ray emission are produced in a region of the jet that extends up to ∼23 pc. This region may correspond to the Compton-loss dominated zone of the flow and its large extent may favor the synchrotron self-Compton mechanism for γ-ray production in the relativistic jet of the quasar 3C 345.