We use a dynamical model to fit data on time trends in HIV prevalence and anti-retroviral treatment (ART) coverage for adults in South Africa. We estimate current and project future trends in HIV incidence, prevalence and AIDS related deaths; in ART coverage and incidence; and in TB notification rates. We consider two scenarios: constant effort under which people continue to be started on treatment at the current rate and expanded treatment and prevention under which testing rates are increased, everyone is started on treatment as soon as they are found to be infected with HIV, and voluntary medical male circumcision, pre-exposure prophylaxis and condom distribution programmes are expanded. HIV incidence and mortality are falling as a result of the expansion of treatment: between 2010 and 2016 incidence fell by 65% and AIDS related deaths fell by 80%. Maintaining a policy of constant effort will lead to further declines in HIV incidence, AIDS related mortality and TB notification rates but will not end AIDS. Implementing a policy of expanded treatment and prevention, as the South African Government intends to do in September 2016, should ensure that by 2020 new infections and deaths will be less than one per thousand adults and the UNAIDS Goal of Ending AIDS by 2030 will be reached. Scaling up voluntary medical male circumcision, pre-exposure prophylaxis and condoms availability will avert some new infections but will save relatively few lives although equity demands that people at very high risk of infection including commercial sex-workers, men-who-have-sex-with-men and young women should have access to the best available methods of prevention. Managing HIV and TB currently costs South Africa about US$2.2 Bn (0.47% of GDP) and this will rise to a peak of US$2.8 Bn in 2018 (0.55% GDP). As treatment is scaled up and prevention made available to those at high risk, the cost will fall to US$ 1.8 Bn in 2030 and US$ 1.0 Bn in 2050 as those that are living with HIV but are on ART die of natural causes. The cost of testing people for HIV is never more than about 8% of the total cost and since testing is the sine qua non of treatment it will be essential to invest sufficient resources in testing. The cost of treating tuberculosis is never more than about 10% of the total and since this is the major cause of AIDS related illness and deaths, efforts should be made to optimise TB treatment. Ending AIDS in the world will depend critically on what happens in South Africa which accounts for 20% of all people living with HIV. The increasing availability of ART has had a major impact on both HIV incidence and AIDS related mortality and the cost of achieving this is affordable. With the intention to make treatment available to all those infected with HIV, starting in September 2016, the South African government is well placed to eliminate HIV as a major threat to public health by 2020 and end AIDS by 2030. Individuals at high risk of infection deserve access to the best available methods of protecting themselves and they will become increasingly important in the final stages of ending the epidemic.