We report on high-S/N subarcsec resolution spectra of M87, obtained with the 4.2-m William Herschel Telescope in the spectral regions around the blue G-band and the IR Ca II triplet. From the spectra we determine the line strengths, the mean and dispersion of the best-fitting Gaussian velocity profiles (i.e. the line-of-sight velocity distributions) and the Gauss-Hermite moments h_3_,...h_6_ that measure deviations from a Gaussian. We find that the main results derived from the two spectral regions agree, in contradiction to recent measurements by Jarvis & Melnick. The observed line strengths have a central minimum in both spectral regions and are consistent with the central luminosity `spike' of M87 being completely non-thermal. The coefficients h_3_,...h_6_ are close to zero at all radii. The velocity dispersion rises from ~270 km s^-1^ at ~15 arcsec to ~305 km s^-1^ at ~5 arcsec, and then to ~400 km s^-1^ at 0.5 arcsec. We model the observed velocity dispersions by solving the Jeans equation for hydrostatic equilibrium. Radial anisotropy (β ~ 0.5) is required in the outer parts to fit the observed velocity dispersion gradient. Near the centre, the data can still be fitted equally well with radially anisotropic models without a central black hole as they can be with less anisotropic models with a central black hole of mass M_BH_ <~ 5 x 10^9^ M_sun_. However, the radially anisotropic Jeans models without a central black hole need not necessarily correspond to a positive and stable distribution function. We study the central velocity profile of isotropic dynamical models with a central black hole. The wings of the velocity profile are more extended than those of a Gaussian. This is due to the stars that orbit close to the hole at high velocities. The wings contribute significantly to the normalization and the dispersion of the velocity profile. A Gaussian fit to the velocity profile is insensitive to the wings, and thus underestimates both the line strength γ and the velocity dispersion σ. In the analysis of real data, this effect is even more pronounced, since low-frequency information is lost due to continuum subtraction. If M87 has a 5 X 10^9^ M_sun_ black hole, we show that for our observational setup, the central line strength will be underestimated by ~2 per cent and the central velocity dispersion by ~8 per cent. Our blue data show two puzzling features, seen also in the data of other authors: the central line strength is too small to be accounted for solely by the dilution from non-thermal light, and the velocity dispersion in the centre is ~30 km s^-1^ smaller than that at R ~ 0.5 arcsec. The presence of a central black hole can provide a qualitative explanation for both features. In addition to the stellar kinematics, we also determine the ionized gas kinematics from the data, by analysing the Hγ emission line. The central velocity dispersion of the ionized gas is very high at ~516 km s^-1^, and drops steeply to ~125 km s^-1^ at R = 2 arcsec. Interpretation of the ionized gas kinematics in terms of a naive isotropic hydrostatic equilibrium model implies the presence of a central black hole of mass M_BH_ = 3 x 10^9^ M_sun_.