A search for the standard model Higgs boson decaying to a charm quark-antiquark pair, H→c¯c, produced in association with a leptonically decaying V (W or Z) boson is presented. The search is performed with proton-proton collisions at √s=13 TeV collected by the CMS experiment, corresponding to an integrated luminosity of 138 fb−1. Novel charm jet identification and analysis methods using machine learning techniques are employed. The analysis is validated by searching for Z→c¯c in VZ events, leading to its first observation at a hadron collider with a significance of 5.7 standard deviations. The observed (expected) upper limit on σ(VH)B(H→c¯c) is 0.94 (0.50+0.22−0.15)pb at 95% confidence level (C.L.), corresponding to 14 (7.6+3.4−2.3) times the standard model prediction. For the Higgs-charm Yukawa coupling modifier, κc, the observed (expected) 95% C.L. interval is 1.1<|κc|<5.5 (|κc|<3.4), the most stringent constraint to date.