HLA-DR molecules bind microbial peptides in an endosomal compartment and present them on the cell surface for CD4 Tcell surveillance. HLA-DM plays a critical role in the endosomal peptide selection process. The structure of the HLA-DM-HLA-DR complex shows major rearrangements of the HLA-DR peptide-binding groove. Flipping of a tryptophan away from the HLA-DR1 P1 pocket enables major conformational changes that position hydrophobic HLA-DR residues into the P1 pocket. These conformational changes accelerate peptide dissociation and stabilize the empty HLA-DR peptide-binding groove. Initially, incoming peptides have access to only part of the HLA-DR groove and need to compete with HLA-DR residues for access to the P2 site and the hydrophobic P1 pocket. This energetic barrier creates a rapid and stringent selection process for the highest-affinity binders. Insertion of peptide residues into the P2 and P1 sites reverses the conformational changes, terminating selection through DM dissociation.