  Atmospheric properties of exoplanets can be constrained with transit
spectroscopy. The signature of atomic sodium NaI, known to be present above the
clouds, is a powerful probe of the upper atmosphere, where it can be best
detected and characterized at high spectral resolution. Our goal is to obtain a
high-resolution transit spectrum of HD189733b in the region around the
resonance doublet of NaI at 589 nm, to characterize the absorption signature
previously detected from space at low resolution. We analyze archival transit
data of HD189733b obtained with the HARPS spectrograph. We retrieve the transit
spectrum and light curve of the planet, implementing corrections for telluric
contamination and planetary orbital motion. We spectrally resolve the NaI D
doublet and measure line contrasts of $0.64\pm0.07\%$ (D2) and $0.40\pm0.07\%$
(D1) and FWHMs of $0.52\pm0.08~\AA$. This corresponds to a detection at the
10-$\sigma$ level of excess of absorption of $0.32\pm0.03\%$ in a passband of
$2\times0.75\ \AA$ centered on each line. We derive temperatures of
$2\,600\pm600$ K and $3270\pm330$ K at altitudes of $9\,800\pm2\,800$ km and
$12\,700\pm2\,600$ km in the NaI D1 and D2 line cores, respectively. We measure
a temperature gradient of $\sim0.2$ K km$^{-1}$ from comparison with
theoretical models. We also detect a blueshift of $0.16\pm0.04\ \AA$ (4
$\sigma$) in the line positions. This blueshift may be due to winds blowing at
$8\pm2$ km s$^{-1}$ in the upper layers of the atmosphere. We demonstrate the
relevance of studying exoplanet atmospheres with high-resolution spectrographs
mounted on 4-meter-class telescopes. Our results pave the way towards in-depth
characterization of physical conditions in the atmospheres of many exoplanetary
systems with future spectrographs such as ESPRESSO on the VLT or HiReS and
METIS on the E-ELT.
