T-cell receptors (TCRs) detect specifically and sensitively a small number of agonist peptide-major histocompatibility complexes (pMHCs) from an ocean of structurally similar self-pMHCs to trigger antigen-specific adaptive immune responses. Despite intense efforts, the mechanism underlying TCR ligand discrimination remains a major unanswered question in immunology. Here we show that a TCR discriminates between closely related peptides by forming TCR-pMHC bonds with different lengths, which precisely control the accessibility of CD3 immunoreceptor tyrosine-based activation motifs (ITAMs) for phosphorylation. Using in situ fluorescence resonance energy transfer (FRET), we measured the intermolecular length of single TCR-pMHC bonds and the intramolecular distance of individual TCR-CD3 complexes at the membrane of live primary T cells. We found that an agonist forms a short TCR-pMHC bond to pull the otherwise sequestered CD3 off the inner leaflet of the plasma membrane, leading to full exposure of its ITAMs for strong phosphorylation. By contrast, a structurally similar weaker peptide forms a longer bond with the TCR, resulting in partial dissociation of CD3 from the membrane and weak phosphorylation. Furthermore, we found that TCR-pMHC bond length determines 2D TCR binding kinetics and affinity, T-cell calcium signaling and T-cell proliferation, governing the entire process of signal reception, transduction and regulation. Thus, our data reveal the fundamental mechanism by which a TCR deciphers the structural differences between foreign antigens and self-peptides via TCR-pMHC bond length to initiate different TCR signaling for ligand discrimination.