A time-dependent, flavour-tagged measurement of CP violation is performed with B0→D+D− and Bs0→Ds+Ds− decays, using data collected by the LHCb detector in proton-proton collisions at a centre-of-mass energy of 13 TeV corresponding to an integrated luminosity of 6 fb−1. In B0→D+D− decays the CP-violation parameters are measured to be \begin{align}
S_{D^{+}D^{-}} & = -0.552 \pm 0.100\,\text{(stat)} \pm 0.010\,\text{(syst)}, \nonumber \newline
C_{D^{+}D^{-}} & = \phantom{-}0.128 \pm0.103\,\text{(stat)} \pm 0.010\,\text{(syst)}. \nonumber \end{align} In Bs0→Ds+Ds− decays the CP-violating parameter formulation in terms of ϕs and ∣λ∣ results in \begin{align}
\phi_{s} & = -0.086 \pm 0.106 \,\text{(stat)} \pm 0.028\,\text{(syst)} \,\text{rad}, \nonumber \newline
|\lambda_{D^{+}_{s}D^{-}_{s}}| & = \phantom{-}1.145 \pm 0.126\,\text{(stat)} \pm 0.031\,\text{(syst)}. \nonumber \end{align} These results represent the most precise single measurement of the CP-violation parameters in their respective channels. For the first time in a single measurement, CP symmetry is observed to be violated in B0→D+D− decays with a significance exceeding six standard deviations.