It was realized in 1772 that small bodies can stably share the same orbit as a planet if they remain near `triangular points' 60° ahead of or behind it in the orbit. Such `Trojan asteroids' have been found co-orbiting with Jupiter, Mars and Neptune. They have not hitherto been found associated with Earth, where the viewing geometry poses difficulties for their detection, although other kinds of co-orbital asteroid (horseshoe orbiters and quasi-satellites) have been observed. Here we report an archival search of infrared data for possible Earth Trojans, producing the candidate 2010 TK7. We subsequently made optical observations which established that 2010 TK7 is a Trojan companion of Earth, librating around the leading Lagrange triangular point, L4. Its orbit is stable over at least ten thousand years.