Here, we search for high-energy gamma-ray emission from the binary neutron star merger GW170817 with the H.E.S.S. Imaging Air Cherenkov Telescopes. The observations presented here have been obtained starting only 5.3 hr after GW170817. The H.E.S.S. target selection identified regions of high probability to find a counterpart of the gravitational-wave event. The first of these regions contained the counterpart SSS17a that has been identified in the optical range several hours after our observations. We can therefore present the first data obtained by a ground-based pointing instrument on this object. A subsequent monitoring campaign with the H.E.S.S. telescopes extended over several days, covering timescales from 0.22 to 5.2 days and energy ranges between $$270\,\mathrm{GeV}$$ to $$8.55\,\mathrm{TeV}$$. No significant gamma-ray emission has been found. The derived upper limits on the very-high-energy gamma-ray flux for the first time constrain non-thermal, high-energy emission following the merger of a confirmed binary neutron star system.