That score gave the Six Nations champions the lead for the second time in the match and they were able to edge their noses in front once more, at 21-20, on the hour.
But, in the end, the Springboks were able to score two tries in the final quarter to ease away and end the two match Prince William Cup series with a 2-0 victory.
Having been bullied off the ball in Bloemfontein, and given the run around for much of the 80 minutes as they went down 43-17, Wales were bold, brave and belligerent as they fought for every scrap of possession.
Instead of being pushed around, they double and triple tackled the South Africans to turn the game into a real contest.
The home side got off to a blistering start with Jean de Villiers and Ricky Januarie scoring tries as they raced into a 14-3 lead. But then scrum half Gareth Cooper raced around the front of a line-out to score and Williams' try made it 15-14 to the visitors.
Butch James edged the Boks back into the lead with a penalty just before the break and then extended the lead at the start of the second half.
His opposite number, Stephen Jones, ensured Wales converted their pressure into points with two penalties in the second half, the latter which gave them that 21-20.
But any thoughts of a first Welsh win on South African soil faded in the final quarter.
James kicked another penalty and then converted close range tries from de Villiers and Bismark du Plessis to put a slightly false face on the scoreboard.