The silicate Earth is strongly depleted in moderately volatile elements (such as lead, zinc, indium and alkali elements) relative to CI chondrites, the meteorites that compositionally most closely resemble the Sun1. This depletion may be explained qualitatively by accretion of 10 to 20 per cent of a volatile-rich body to a reduced volatile-free proto-Earth2,3, followed by partial extraction of some elements to the core1. However, there are several unanswered questions regarding the sources of Earth’s volatiles4,5, notably the overabundance of indium in the silicate Earth. Here we examine the melting processes that occurred during accretion on Earth and precursor bodies and report vaporization experiments under conditions of fixed temperature and oxygen fugacity. We find that the pattern of volatile element depletion in the silicate Earth is consistent with partial melting and vaporization rather than with simple accretion of a volatile-rich chondrite-like body. We argue that melting and vaporization on precursor bodies and possibly during the giant Moon-forming impact6,7,8were responsible for establishing the observed abundances of moderately volatile elements in Earth.