A search for the Standard Model Higgs boson decaying to a pair of charm quarks is presented. The analysis targets the associated production in proton-proton collisions of the Higgs boson with a or boson decaying into leptons. The dataset delivered by the LHC at a centre-of-mass energy of TeV and recorded by the ATLAS detector corresponds to an integrated luminosity of 139 fb. Flavour tagging algorithms are used to identify jets originating from the hadronisation of charm quarks. The analysis method is validated with the simultaneous measurement of and production, with observed (expected) significances of 2.6~(2.2) standard deviations above the background-only hypothesis for the process and 3.8~(4.6) standard deviations for the process. The search yields an observed (expected) limit of () times the predicted cross-section times branching fraction for a Higgs boson with a mass of GeV, corresponding to an observed (expected) constraint on the charm Yukawa coupling modifier |\kappa_c| < 8.5~(12.4), at the 95% confidence level.