A search for charge-parity (CP) violation in D^{0}→K^{-}K^{+} and D^{0}→π^{-}π^{+} decays is reported, using pp collision data corresponding to an integrated luminosity of 5.9 fb^{-1} collected at a center-of-mass energy of 13 TeV with the LHCb detector. The flavor of the charm meson is inferred from the charge of the pion in D^{*}(2010)^{+}→D^{0}π^{+} decays or from the charge of the muon in B[over ¯]→D^{0}μ^{-}ν[over ¯]_{μ}X decays. The difference between the CP asymmetries in D^{0}→K^{-}K^{+} and D^{0}→π^{-}π^{+} decays is measured to be ΔA_{CP}=[-18.2±3.2(stat)±0.9(syst)]×10^{-4} for π-tagged and ΔA_{CP}=[-9±8(stat)±5(syst)]×10^{-4} for μ-tagged D^{0} mesons. Combining these with previous LHCb results leads to ΔA_{CP}=(-15.4±2.9)×10^{-4}, where the uncertainty includes both statistical and systematic contributions. The measured value differs from zero by more than 5 standard deviations. This is the first observation of CP violation in the decay of charm hadrons.