Background: We assessed risk factors for viremia and drug resistance among long-term recipients of antiretroviral therapy (ART) in South Africa., Methods: In 2008, we conducted a cross-sectional study among patients receiving ART for 12 months or more. Genotypic resistance testing was performed on individuals with a viral load higher than 400 RNA copies/ml. Multiple logistic regression analysis was used to assess associations., Results: Of 998 participants, 75% were women with a median age of 41 years. Most (64%) had been on treatment for more than 3 years. The prevalence of viremia was 14% (n = 139): 12% (102/883) on first-line [i.e. nonnucleoside reverse-transcriptase inhibitor (NNRTI)-based regimen] and 33% (37/115) on second-line (i.e. protease inhibitor (PI)-based regimen) ART. Of viremic patients, 78% had drug resistance mutations. For NRTIs, NNRTIs and PIs, the prevalence of mutations was 64, 81 and 2%, respectively, among first-line failures and 29, 54 and 6%, respectively, among second-line failures. M184V/I, K103N and V106A/M were the most common mutations. Significant risk factors associated with viremia on first-line regimen included concurrent tuberculosis treatment [odds ratio (OR) 6.4, 95% confidence interval (CI) 2.2-18.8, P < 0.01] and a recent history of poor adherence (OR 2.7, 1.3-5.6, P = 0.01). Among second-line failures, attending a public clinic (OR 4.6, 95% CI 1.8-11.3, P < 0.01) and not having a refrigerator at home (OR 6.7, 95% CI 1.2-37.5, P = 0.03) were risk factors for virological failure., Conclusion: Risk factors for viral failure were line regimen dependent. Second-line ART recipients had a higher rate of viremia, albeit with infrequent PI drug resistance mutations. Measures to maintain effective virologic suppression should include increased adherence counseling, attention to concomitant tuberculosis treatment and heat-stable formulations of second-line ART regimens.