To estimate the epidemiological impact of past HIV interventions and the magnitude and contribution of undiagnosed HIV among different risk groups on new HIV acquisitions in Côte d'Ivoire, Mali and Senegal. HIV transmission dynamic models among the overall population and key populations [female sex workers (FSW), their clients, and MSM]. Models were independently parameterized and calibrated for each set of country-specific demographic, behavioural, and epidemiological data. We estimated the fraction of new HIV infections over 2012-2021 averted by condom use and antiretroviral therapy (ART) uptake among key population and nonkey population, the direct and indirect contribution of specific groups to new infections [transmission population-attributable fraction (tPAF)] over 2012-2021 due to prevention gaps, and the distribution of undiagnosed PWH by risk group in January 2022 and their tPAF over 2022-2031. Condom use and ART may have averted 81-88% of new HIV infections over 2012-2021 across countries, mostly because of condom use by key population. The tPAF of all key populations combined over 2012-2021 varied between 27% (Côte d'Ivoire) and 79% (Senegal). Male key population (clients of FSW and MSM) contributed most to new infections (>60% in Mali and Senegal) owing to their higher HIV prevalence and larger prevention gaps. In 2022, men represented 56% of all PWH with an undiagnosed infection in Côte d'Ivoire (male key population = 15%), 46% in Mali (male key population = 23%), and 69% in Senegal (male key population = 55%). If HIV testing and ART initiation rates remain at current levels, 20% of new HIV infections could be due to undiagnosed key population PWH in Côte d'Ivoire over 2022-2031, 53% in Mali, and 65% in Senegal. Substantial HIV diagnosis gaps remain in Western Africa, especially among male key population. Addressing these gaps is key to impacting the HIV epidemics in the region and achieving the goal of ending AIDS by 2030.