  We present a determination of the charm quark mass in lattice QCD with three
active quark flavours. The calculation is based on PCAC masses extracted from
$N_\mathrm{f}=2+1$ flavour gauge field ensembles at five different lattice
spacings in a range from 0.087 fm down to 0.039 fm. The lattice action consists
of the $\mathrm{O}(a)$ improved Wilson-clover action and a tree-level improved
Symanzik gauge action. Quark masses are non-perturbatively $\mathrm{O}(a)$
improved employing the Symanzik-counterterms available for this discretisation
of QCD. To relate the bare mass at a specified low-energy scale with the
renormalisation group invariant mass in the continuum limit, we use the
non-pertubatively known factors that account for the running of the quark
masses as well as for their renormalisation at hadronic scales. We obtain the
renormalisation group invariant charm quark mass at the physical point of the
three-flavour theory to be $M_\mathrm{c} = 1486(21)\,$MeV. Combining this
result with five-loop perturbation theory and the corresponding decoupling
relations in the $\overline{\mathrm{MS}}$ scheme, one arrives at a result for
the renormalisation group invariant charm quark mass in the four-flavour theory
of $M_\mathrm{c}(N_\mathrm{f}=4) = 1548(23)\,$MeV. In the
$\overline{\mathrm{MS}}$ scheme, and at finite energy scales conventional in
phenomenology, we quote
$m^{\overline{\mathrm{MS}}}_{\mathrm{c}}(m^{\overline{\mathrm{MS}}}_{\mathrm{c}};
N_\mathrm{f}=4)=1296(19)\,\mathrm{MeV}$ and
$m^{\overline{\mathrm{MS}}}_{\mathrm{c}}(3\,\mathrm{GeV};
N_\mathrm{f}=4)=1007(16)\,\mathrm{MeV}$ for the renormalised charm quark mass
