There is limited data on human immunodeficiency virus (HIV) evolutionary trends in African populations. We evaluated changes in HIV viral diversity and genetic divergence in southern Uganda over a 24-year period spanning the introduction and scale-up of HIV prevention and treatment programs using HIV sequence and survey data from the Rakai Community Cohort Study, an open longitudinal population-based HIV surveillance cohort. Gag (p24) and env (gp41) HIV data were generated from people living with HIV (PLHIV) in 31 inland semi-urban trading and agrarian communities (1994-2018) and four hyperendemic Lake Victoria fishing communities (2011-2018) under continuous surveillance. HIV subtype was assigned using the Recombination Identification Program with phylogenetic confirmation. Inter-subtype diversity was evaluated using the Shannon diversity index, and intra-subtype diversity with the nucleotide diversity and pairwise TN93 genetic distance. Genetic divergence was measured using root-to-tip distance and pairwise TN93 genetic distance analyses. Demographic history of HIV was inferred using a coalescent-based Bayesian Skygrid model. Evolutionary dynamics were assessed among demographic and behavioral population subgroups, including by migration status. 9931 HIV sequences were available from 4999 PLHIV, including 3060 and 1939 persons residing in inland and fishing communities, respectively. In inland communities, subtype A1 viruses proportionately increased from 14.3% in 1995 to 25.9% in 2017 (P < .001), while those of subtype D declined from 73.2% in 1995 to 28.2% in 2017 (P < .001). The proportion of viruses classified as recombinants significantly increased by nearly four-fold from 12.2% in 1995 to 44.8% in 2017. Inter-subtype HIV diversity has generally increased. While intra-subtype p24 genetic diversity and divergence leveled off after 2014, intra-subtype gp41 diversity, effective population size, and divergence increased through 2017. Intra- and inter-subtype viral diversity increased across all demographic and behavioral population subgroups, including among individuals with no recent migration history or extra-community sexual partners. This study provides insights into population-level HIV evolutionary dynamics following the scale-up of HIV prevention and treatment programs. Continued molecular surveillance may provide a better understanding of the dynamics driving population HIV evolution and yield important insights for epidemic control and vaccine development.