The provision of ART in South Africa has transformed the HIV epidemic, resulting in an increase in life expectancy by over 10 years. Despite this, nearly 2million people living with HIV are not on treatment. The objective of this study was to develop and externally validate a practical risk assessment tool to identify people with HIV (PWH) at highest risk for attrition from care after testing. A machine learning model incorporating clinical and psychosocial factors was developed in a primary cohort of 498 PWH. LASSO regression analysis was used to optimize variable selection. Multivariable logistic regression analysis was applied to build a model using 80% of the primary cohort as a training dataset and validated using the remaining 20% of the primary cohort and data from an independent cohort of 96 participants. The risk score was developed using the Sullivan and D'Agostino point based method. Of 498 participants with mean age 35.7 years, 192 (38%) did not initiate ART after diagnosis. Controlling for site, factors associated with non-engagement in care included being < 35 years, feeling abandoned by God, maladaptive coping strategies using alcohol or other drugs, no difficulty concentrating, and having high levels of confidence in one's ability to handle personal challenges. An effective risk score can enable clinicians and implementers to focus on tailoring care for those most in need of ongoing support. Further research should focus on potential strategies to enhance the generalizability and evaluate the implementation of the proposed risk prediction model in HIV treatment programs.