Earth is the only planet known to have continents, although how they formed and evolved is unclear. Here using the oxygen isotope compositions of dated magmatic zircon, we show that the Pilbara Craton in Western Australia, Earth’s best-preserved Archaean (4.0–2.5 billion years ago (Ga)) continental remnant, was built in three stages. Stage 1 zircons (3.6–3.4 Ga) form two age clusters with one-third recording submantle δ18O, indicating crystallization from evolved magmas derived from hydrothermally altered basaltic crust like that in modern-day Iceland1,2. Shallow melting is consistent with giant impacts that typified the first billion years of Earth history3–5. Giant impacts provide a mechanism for fracturing the crust and establishing prolonged hydrothermal alteration by interaction with the globally extensive ocean6–8. A giant impact at around 3.6 Ga, coeval with the oldest low-δ18O zircon, would have triggered massive mantle melting to produce a thick mafic–ultramafic nucleus9,10. A second low-δ18O zircon cluster at around 3.4 Ga is contemporaneous with spherule beds that provide the oldest material evidence for giant impacts on Earth11. Stage 2 (3.4–3.0 Ga) zircons mostly have mantle-like δ18O and crystallized from parental magmas formed near the base of the evolving continental nucleus12. Stage 3 (<3.0 Ga) zircons have above-mantle δ18O, indicating efficient recycling of supracrustal rocks. That the oldest felsic rocks formed at 3.9–3.5 Ga (ref. 13), towards the end of the so-called late heavy bombardment4, is not a coincidence.