Cellular immunity against viral infection and tumour cells depends on antigen presentation by major histocompatibility complex class I (MHC I) molecules. Intracellular antigenic peptides are transported into the endoplasmic reticulum by the transporter associated with antigen processing (TAP) and then loaded onto the nascent MHC I molecules, which are exported to the cell surface and present peptides to the immune system. Cytotoxic T lymphocytes recognize non-self peptides and program the infected or malignant cells for apoptosis. Defects in TAP account for immunodeficiency and tumour development. To escape immune surveillance, some viruses have evolved strategies either to downregulate TAP expression or directly inhibit TAP activity. So far, neither the architecture of TAP nor the mechanism of viral inhibition has been elucidated at the structural level. Here we describe the cryo-electron microscopy structure of human TAP in complex with its inhibitor ICP47, a small protein produced by the herpes simplex virus I. Here we show that the 12 transmembrane helices and 2 cytosolic nucleotide-binding domains of the transporter adopt an inward-facing conformation with the two nucleotide-binding domains separated. The viral inhibitor ICP47 forms a long helical hairpin, which plugs the translocation pathway of TAP from the cytoplasmic side. Association of ICP47 precludes substrate binding and prevents nucleotide-binding domain closure necessary for ATP hydrolysis. This work illustrates a striking example of immune evasion by persistent viruses. By blocking viral antigens from entering the endoplasmic reticulum, herpes simplex virus is hidden from cytotoxic T lymphocytes, which may contribute to establishing a lifelong infection in the host.