  Pebbles of millimeter sizes are abundant in protoplanetary discs around young
stars. Chondrules inside primitive meteorites - formed by melting of dust
aggregate pebbles or in impacts between planetesimals - have similar sizes. The
role of pebble accretion for terrestrial planet formation is nevertheless
unclear. Here we present a model where inwards-drifting pebbles feed the growth
of terrestrial planets. The masses and orbits of Venus, Earth, Theia (which
later collided with the Earth to form the Moon) and Mars are all consistent
with pebble accretion onto protoplanets that formed around Mars' orbit and
migrated to their final positions while growing. The isotopic compositions of
Earth and Mars are matched qualitatively by accretion of two generations of
pebbles, carrying distinct isotopic signatures. Finally, we show that the water
and carbon budget of Earth can be delivered by pebbles from the early
generation before the gas envelope became hot enough to vaporise volatiles.
