The new CARMENES instrument comprises two high-resolution and high-stability spectrographs that are used to search for habitable planets around M dwarfs in the visible and near-infrared regime via the Doppler technique. Characterising our target sample is important for constraining the physical properties of any planetary systems that are detected. The aim of this paper is to determine the fundamental stellar parameters of the CARMENES M-dwarf target sample from high-resolution spectra observed with CARMENES. We also include several M-dwarf spectra observed with other high-resolution spectrographs, that is CAFE, FEROS, and HRS, for completeness. We used a {chi}^2^ method to derive the stellar parameters effective temperature T_eff, surface gravity log g, and metallicity [Fe/H] of the target stars by fitting the most recent version of the PHOENIX-ACES models to high-resolution spectroscopic data. These stellar atmosphere models incorporate a new equation of state to describe spectral features of low-temperature stellar atmospheres. Since Teff, logg, and [Fe/H] show degeneracies, the surface gravity is determined independently using stellar evolutionary models. We derive the stellar parameters for a total of 300 stars. The fits achieve very good agreement between the PHOENIX models and observed spectra. We estimate that our method provides parameters with uncertainties of {sigma}_Teff_=51K, {sigma}_logg_=0.07, and {sigma}_[Fe/H]_=0.16, and show that atmosphere models for low-mass stars have significantly improved in the last years. Our work also provides an independent test of the new PHOENIX-ACES models, and a comparison for other methods using low-resolution spectra. In particular, our effective temperatures agree well with literature values, while metallicities determined with our method exhibit a larger spread when compared to literature results.