We measure the escape speed curve of the Milky Way based on the analysis of the velocity distribution of $sim 2850$ counter-rotating halo stars from the Gaia DR2. The distances were estimated through the StarHorse code, and only stars with distance errors smaller than 10 per cent were used in the study. The escape speed curve is measured at Galactocentric radii ranging from $sim 5$ kpc to $sim 10.5$ kpc. The local Galactic escape at the Suns position is estimated to be $v_mathrm{e}(r_odot)=580 pm 63~mathrm{km~s^{-1}}$, and it rises towards the Galactic center. Defined as the minimum speed required to reach three virial radii, our estimate of the escape speed as a function of radius implies, for a Navarro-Frenk-White profile and local circular velocity of $240~mathrm{km~s^{-1}}$, a dark matter mass $M_{200}=1.28^{+0.68}_{-0.50} times 10^{12}~M_odot$ and a high concentration $c_{200}=11.09^{+2.94}_{-1.79}$. Assuming the mass-concentration relation of $Lambda$CDM, we get $M_{200}=1.55_{-0.51}^{+0.64}times 10^{12}~M_odot$, $c_{200}=7.93_{-0.27}^{+0.33}$, for a local circular velocity of $228~mathrm{km~s^{-1}}$.