ABCG2 is a transporter protein of the ATP-binding-cassette (ABC) family that is expressed in the plasma membrane in cells of various tissues and tissue barriers, including the blood-brain, blood-testis and maternal-fetal barriers1-4. Powered by ATP, it translocates endogenous substrates, affects the pharmacokinetics of many drugs and protects against a wide array of xenobiotics, including anti-cancer drugs5-12. Previous studies have revealed the architecture of ABCG2 and the structural basis of its inhibition by small molecules and antibodies13,14. However, the mechanisms of substrate recognition and ATP-driven transport are unknown. Here we present high-resolution cryo-electron microscopy (cryo-EM) structures of human ABCG2 in a substrate-bound pre-translocation state and an ATP-bound post-translocation state. For both structures, we used a mutant containing a glutamine replacing the catalytic glutamate (ABCG2EQ), which resulted in reduced ATPase and transport rates and facilitated conformational trapping for structural studies. In the substrate-bound state, a single molecule of estrone-3-sulfate (E1S) is bound in a central, hydrophobic and cytoplasm-facing cavity about halfway across the membrane. Only one molecule of E1S can bind in the observed binding mode. In the ATP-bound state, the substrate-binding cavity has collapsed while an external cavity has opened to the extracellular side of the membrane. The ATP-induced conformational changes include rigid-body shifts of the transmembrane domains, pivoting of the nucleotide-binding domains (NBDs), and a change in the relative orientation of the NBD subdomains. Mutagenesis and in vitro characterization of transport and ATPase activities demonstrate the roles of specific residues in substrate recognition, including a leucine residue that forms a 'plug' between the two cavities. Our results show how ABCG2 harnesses the energy of ATP binding to extrude E1S and other substrates, and suggest that the size and binding affinity of compounds are important for distinguishing substrates from inhibitors.