We solve the spectral synthesis problem for exponential systems on an interval. Namely, we prove that any complete and minimal system of exponentials $\{e^{i\lambda_n t}\}$ in $L^2(-a,a)$ is hereditarily complete up to a one-dimensional defect. This means that there is at most one (up to a constant factor) function $f$ which is orthogonal to all the summands in its formal Fourier series $\sum_n (f,\tilde e_n) e^{i\lambda_n t}$, where $\{\tilde e_n\}$ is the system biorthogonal to $\{e^{i\lambda_n t}\}$. However, this one-dimensional defect is possible and, thus, there exist nonhereditarily complete exponential systems. Analogous results are obtained for systems of reproducing kernels in de Branges spaces. For a wide class of de Branges spaces we construct nonhereditarily complete systems of reproducing kernels, thus answering a question posed by N. Nikolski.