HIV incidence has been declining in Africa with scale-up of HIV interventions. However, there is limited data on HIV evolutionary trends in African populations with waning epidemics. We evaluated changes in HIV viral diversity and genetic divergence in southern Uganda over a twenty-five-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 persons living with HIV (PLHIV) in 31 inland semi-urban trading and agrarian communities (1994 to 2018) and four hyperendemic Lake Victoria fishing communities (2011 to 2018) under continuous surveillance. HIV subtype was assigned using the Recombination Identification Program with phylogenetic confirmation. Inter-subtype diversity was estimated 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. Evolutionary dynamics were assessed among demographic and behavioral sub-groups, including by migration status. 9,931 HIV sequences were available from 4,999 PLHIV, including 3,060 and 1,939 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<0.001), while those of subtype D declined from 73.2% in 1995 to 28.2% in 2017 (p<0.001). The proportion of viruses classified as recombinants significantly increased by more than four-fold. Inter-subtype HIV diversity has generally increased. While p24 intra-subtype genetic diversity and divergence leveled off after 2014, diversity and divergence of gp41 increased through 2017. Inter- and intra-subtype viral diversity increased across all population sub-groups, including among individuals with no recent migration history or extra-community sexual partners. This study provides insights into population-level HIV evolutionary dynamics in declining African HIV epidemics 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.