Juan Smith found space on the right and off-loaded to scrum-half Januarie to claim the second try, which James converted.
Wales immediately cut the 14-3 deficit when Jonathan Thomas cleverly laid off to Gloucester scrum-half Cooper at the front of a line-out and he broke free to race over.
Jones' conversion put them four points behind, but James had the chance to open up the gap again with a penalty only to miss, ending his run of 10 successful kicks over the two Tests.
And it proved costly as Ospreys wing Williams produced another moment of brilliance with his 43rd Wales try.
Stephen Jones had a mixed day in front of the posts
The Springboks lost possession just inside their own half, Williams picked up the loose ball and raced past five players to go over near the corner.
Williams was then called into action at the other end just before the break when he intercepted James' pass.
But James made sure South Africa went in ahead at the break when Blues centre Jamie Roberts was penalised at the line.
Jones did have the chance to change that in overtime, but sent his long-range penalty wide.
Wales came out on the attack in the second half enjoying more time on the ball, but it was the hosts who secured the first points.
Roberts infringed at the ruck allowing James to kick South Africa into a 20-15 lead.
But Wales were not ready to give up and Jones clawed back another three points after Mtawarira failed to roll away at a ruck.
And they went ahead with 20 minutes to go when Jones successfully kicked again.
The Springboks brought on all of their big-guns and regained the lead through another James kick.
It seemed to give them some more impetus and Percy Montgomery was halted at the line before de Villiers made sure diving over with James converting.
They continued to press and finally got their fourth score through Bismarck Du Plessis after a quick penalty.
On paper, the win looked far more convincing for South Africa but Wales showed that they do still have the fight that made them champions of the northern hemisphere.
South Africa: Jantjes, Chavhanga, Jacobs, de Villiers, Habana, James, Januarie, Mtawarira, Smit, B. Botha, B. Botha, Matfield, Watson, Smith, Spies. Replacements: Montgomery for Chavhanga (64), Steyn for Jacobs (59), Conradie for Januarie (77), Steenkamp for Mtawarira (60), du Plessis for Smit (59), Bekker for B. Botha (64), Kankowski for Spies (59).
Wales: Hook, M. Jones, Shanklin, Roberts, Williams, S. Jones, Cooper, Jenkins, Hibbard, R. Thomas, Gough, A. Jones, R. Jones, J. Thomas, Delve. Replacements: James for M. Jones (78), Bishop for Shanklin (69), Fury for Cooper (76), T. Thomas for Hibbard (72), D. Jones for R. Thomas (71), Evans for R. Jones (69), D. Jones for Delve (24).
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.