In real-time quantum feedback protocols, the record of a continuous measurement is used to stabilize a desired quantum state. Recent years have seen successful applications of these protocols in a variety of well-isolated micro-systems, including microwave photons and superconducting qubits. However, stabilizing the quantum state of a tangibly massive object, such as a mechanical oscillator, remains very challenging: the main obstacle is environmental decoherence, which places stringent requirements on the timescale in which the state must be measured. Here we describe a position sensor that is capable of resolving the zero-point motion of a solid-state, 4.3-megahertz nanomechanical oscillator in the timescale of its thermal decoherence, a basic requirement for real-time (Markovian) quantum feedback control tasks, such as ground-state preparation. The sensor is based on evanescent optomechanical coupling to a high-Q microcavity, and achieves an imprecision four orders of magnitude below that at the standard quantum limit for a weak continuous position measurement--a 100-fold improvement over previous reports--while maintaining an imprecision-back-action product that is within a factor of five of the Heisenberg uncertainty limit. As a demonstration of its utility, we use the measurement as an error signal with which to feedback cool the oscillator. Using radiation pressure as an actuator, the oscillator is cold damped with high efficiency: from a cryogenic-bath temperature of 4.4 kelvin to an effective value of 1.1 ± 0.1 millikelvin, corresponding to a mean phonon number of 5.3 ± 0.6 (that is, a ground-state probability of 16 per cent). Our results set a new benchmark for the performance of a linear position sensor, and signal the emergence of mechanical oscillators as practical subjects for measurement-based quantum control.