Mycobacterium tuberculosis remains a leading cause of death worldwide, especially among individuals infected with HIV. Whereas phylogenetic analysis has revealed M. tuberculosis spread throughout history and in local outbreaks, much less is understood about its dissemination within the body. Here we report genomic analysis of 2,693 samples collected post mortem from lung and extrapulmonary biopsies of 44 subjects in KwaZulu-Natal, South Africa, who received minimal antitubercular treatment and most of whom were HIV seropositive. We found that purifying selection occurred within individual patients, without the need for patient-to-patient transmission. Despite negative selection, mycobacteria diversified within individuals to form sublineages that co-existed for years. These sublineages, as well as distinct strains from mixed infections, were differentially distributed throughout the lung, suggesting temporary barriers to pathogen migration. As a consequence, samples taken from the upper airway often captured only a fraction of the population diversity, challenging current methods of outbreak tracing and resistance diagnostics. Phylogenetic analysis indicated that dissemination from the lungs to extrapulmonary sites was as frequent as between lung sites, supporting the idea of similar migration routes within and between organs, at least in subjects with HIV. Genomic diversity therefore provides a record of pathogen diversification and repeated dissemination across the body.