Massive internal migration from rural to urban areas poses new challenges for tuberculosis control in China. We aimed to combine genomic, spatial, and epidemiological data to describe the dynamics of tuberculosis in an urban setting with large numbers of migrants. We did a population-based study of culture-positive Mycobacterium tuberculosis isolates in Songjiang, Shanghai. We used whole-genome sequencing to discriminate apparent genetic clusters of M tuberculosis sharing identical variable-number-tandem-repeat (VNTR) patterns, and analysed the relations between proximity of residence and the risk of genomically clustered M tuberculosis. Finally, we used genomic, spatial, and epidemiological data to estimate time of infection and transmission links among migrants and residents. Between Jan 1, 2009, and Dec 31, 2015, 1620 cases of culture-positive tuberculosis were recorded, 1211 (75%) of which occurred among internal migrants. 150 (69%) of 218 people sharing identical VNTR patterns had isolates within ten single-nucleotide polymorphisms (SNPs) of at least one other strain, consistent with recent transmission of M tuberculosis. Pairs of strains collected from individuals living in close proximity were more likely to be genetically similar than those from individuals who lived far away-for every additional km of distance between patients' homes, the odds that genotypically matched strains were within ten SNPs of each other decreased by about 10% (OR 0·89 [95% CI 0·87-0·91]; p<0·0001). We inferred that transmission from residents to migrants occurs as commonly as transmission from migrants to residents, and we estimated that more than two-thirds of migrants in genomic clusters were infected locally after migration. The primary mechanism driving local incidence of tuberculosis in urban centres is local transmission between both migrants and residents. Combined analysis of epidemiological, genomic, and spatial data contributes to a richer understanding of local transmission dynamics and should inform the design of more effective interventions. National Natural Science Foundation of China, National Science and Technology Major Project of China, and US National Institutes of Health.