The scale-up of antiretroviral therapy (ART) in South Africa substantially reduced AIDS-related deaths and new HIV infections. However, its success is threatened by the emergence of resistance to non-nucleoside reverse-transcriptase inhibitors (NNRTI). The MARISA (Modelling Antiretroviral drug Resistance In South Africa) model presented here aims at investigating the time trends and factors driving NNRTI resistance in South Africa. MARISA is a compartmental model that includes the key aspects of the local HIV epidemic: continuum of care, disease progression, and gender. The dynamics of NNRTI resistance emergence and transmission are then added to this framework. Model parameters are informed using data from HIV cohorts participating in the International epidemiology Databases to Evaluate AIDS (IeDEA) and literature estimates, or fitted to UNAIDS estimates. Using this novel approach of triangulating clinical and resistance data from various sources, MARISA reproduces the time trends of HIV in South Africa in 2005-2016, with a decrease in new infections, undiagnosed individuals, and AIDS-related deaths. MARISA captures the dynamics of the spread of NNRTI resistance: high levels of acquired drug resistance (ADR, in 83% of first-line treatment failures in 2016), and increasing transmitted drug resistance (TDR, in 8.1% of ART initiators in 2016). Simulation of counter-factual scenarios reflecting alternative public health policies shows that increasing treatment coverage would have resulted in fewer new infections and deaths, at the cost of higher TDR (11.6% in 2016 for doubling the treatment rate). Conversely, improving switching to second-line treatment would have led to lower TDR (6.5% in 2016 for doubling the switching rate) and fewer new infections and deaths. Implementing drug resistance testing would have had little impact. The rapid ART scale-up and inadequate switching to second-line treatment were the key drivers of the spread of NNRTI resistance in South Africa. However, even though some interventions could have substantially reduced the level of NNRTI resistance, no policy including NNRTI-based first line regimens could have prevented this spread. Thus, by combining epidemiological data on HIV in South Africa with biological data on resistance evolution, our modelling approach identified key factors driving NNRTI resistance, highlighting the need of alternative first-line regimens.