A search for lepton flavour violating decays of the Higgs boson in the μτ and eτ decay modes is presented. The search is based on a data set corresponding to an integrated luminosity of 35.9 fb−1 of proton-proton collisions collected with the CMS detector in 2016, at a centre-of-mass energy of 13 TeV. No significant excess over the standard model expectation is observed. The observed (expected) upper limits on the lepton flavour violating branching fractions of the Higgs boson are ℬ(H → μτ) < 0.25% (0.25%) and ℬ(H → eτ) < 0.61% (0.37%), at 95% confidence level. These results are used to derive upper limits on the off-diagonal μτ and eτ Yukawa couplings |Yμτ|2+|Yτμ|2−−−−−−−−−−−√<1.43×10−3 and |Yeτ|2+|Yτe|2−−−−−−−−−−−√<2.26×10−3 at 95% confidence level. The limits on the lepton flavour violating branching fractions of the Higgs boson and on the associated Yukawa couplings are the most stringent to date.