  Density-functional theory within a Berry-phase formulation of the dynamical
polarization is used to determine the second-order susceptibility $\chi^{(2)}$
of lithium niobate (LiNbO$_3$). Defect trapped polarons and bipolarons are
found to strongly enhance the nonlinear susceptibility of the material, in
particular if localized at Nb$_\mathrm{V}$-V$_{\mathrm{Li}}$ defect pairs. This
is essentially a consequence of the polaronic excitation resulting in
relaxation-induced gap states. The occupation of these levels leads to strongly
enhanced $\chi^{(2)}$ coefficients and allows for the spatial and transient
modification of the second-harmonic generation of macroscopic samples.
