Terrestrial planets are thought to have formed through collisions between large planetary embryos of diameter ∼1,000-5,000 km. For Earth, the last of these collisions involved an impact by a Mars-size embryo that formed the Moon 50-150 million years (Myr) after the birth of the Solar System. Although model simulations of the growth of terrestrial planets can reproduce the mass and dynamical parameters of the Earth and Venus, they fall short of explaining the small size of Mars. One possibility is that Mars was a planetary embryo that escaped collision and merging with other embryos. To assess this idea, it is crucial to know Mars' accretion timescale, which can be investigated using the (182)Hf-(182)W decay system in shergottite-nakhlite-chassignite meteorites. Nevertheless, this timescale remains poorly constrained owing to a large uncertainty associated with the Hf/W ratio of the Martian mantle and as a result, contradicting timescales have been reported that range between 0 and 15 Myr (refs 6-10). Here we show that Mars accreted very rapidly and reached about half of its present size in only 1.8(+0.9)(-1.0) Myr or less, which is consistent with a stranded planetary embryo origin. We have found a well-defined correlation between the Th/Hf and (176)Hf/(177)Hf ratios in chondrites that reflects remobilization of Lu and Th during parent-body processes. Using this relationship, we estimate the Hf/W ratio in Mars' mantle to be 3.51 ± 0.45. This value is much more precise than previous estimates, which ranged between 2.6 and 5.0 (ref. 6), and lifts the large uncertainty that plagued previous estimates of the age of Mars. Our results also demonstrate that Mars grew before dissipation of the nebular gas when ∼100-km planetesimals, such as the parent bodies of chondrites, were still being formed. Mars' accretion occurred early enough to allow establishment of a magma ocean powered by decay of (26)Al.