We present a new approach to the problem of computing the zeta function of a hypersurface over a finite field. For a hypersurface defined by a polynomial of degree $d$ in $n$ variables over the field of $q$ elements, one desires an algorithm whose running time is a polynomial function of $d^n \log(q)$. (Here we assume $d \geq 2$, for otherwise the problem is easy.) The case $n = 1$ is related to univariate polynomial factorisation and is comparatively straightforward. When $n = 2$ one is counting points on curves, and the method of Schoof and Pila yields a complexity of $\log(q)^{C_d}$, where the function $C_d$ depends exponentially on $d$. For arbitrary $n$, the theorem of the author and Wan gives a complexity which is a polynomial function of $(pd^n \log(q))^n$, where $p$ is the characteristic of the field. A complexity estimate of this form can also be achieved for smooth hypersurfaces using the method of Kedlaya, although this has only been worked out in full for curves. The new approach we present should yield a complexity which is a small polynomial function of $pd^n\log(q)$. In this paper, we work this out in full for Artin–Schreier hypersurfaces defined by equations of the form $Z^p - Z = f$, where the polynomial $f$ has a diagonal leading form. The method utilises a relative $p$-adic cohomology theory for families of hypersurfaces, due in essence to Dwork. As a corollary of our main theorem, we obtain the following curious result. Let $f$ be a multivariate polynomial with integer coefficients whose leading form is diagonal. There exists an explicit deterministic algorithm which takes as input a prime $p$, outputs the number of solutions to the congruence equation $f = 0 \bmod{p}$, and runs in ${\mathcal O}(p^{2 + \varepsilon})$ bit operations, for any $\varepsilon > 0$. This improves upon the elementary estimate of ${\mathcal O}(p^{n-1 + \varepsilon})$ bit operations, where $n$ is the number of variables, which can be achieved using Berlekamp's root counting algorithm.