Wales went into half-time trailing 14-12 with their tries coming from Jonny Vaughton and Newport Gwent Dragon Rhys Oakley, but South Africa made the better start in the second-half and converted tries from Fabian Juries and Tobela Mdaka gave them a 28-12 lead.
Second-half replacement Tal Selley sparked their revival and with a minute remaining Rhys Williams made it 28-24. It looked as if time would run out for Wales but deep into injury time James Hook dived over in the corner to spark amazing scenes at the Telstra Dome.
The Neath man was probably Wales best player in the 2006 Commonwealth Games sevens tournament and it was fitting that he was the man who secured victory. He said: "I can't really believe it and I am a bit lost for words.
"It has been such an amazing season for me with Neath and the U21 and now this. It means so much to me and the boys. We are still just learning the game but have made our mark here. There has been no secret to our success, just hard work and a strong team ethic. I never thought it was over and just saw a gap and went for it, we are all delighted."
Coach Dai Rees added: "We have beaten some quality teams to win this and I hope people realise back home that this is a very high standard of rugby and I hope we continue to play it in Wales because everyone has benefited from it.
"People like Rhys Williams deserve a special mention. This is the first time he has played sevens rugby and he has been absolutely amazing. It has been a hard season for him and hopefully this will spark his international comeback and a return to form at regional level."
Wales crashed out of the Sevens Medal competition after losing 26-7 to Fiji in the quarter-finals. Rees's men started poorly going into half time with a 19 point deficit to make up and they were always playing catch up as a result.
First-half tries from Sireli Naqelevuki (2) and Jone Daunivucu gave the Fijians a 19-0 lead with the Welsh struggling to get their hands on the ball. To their credit they fought back after the break and a try from Penzance scrum-half Rhodri Mcatee gave them some hope.
James Hook converted and soon after Robin Sowden-Taylor had a chance to reduce the deficit further, but spilled the ball and with that went Wales's last chance of a comeback. In fact it was Fiji who scored next, William Ryder scored it, running unchallenged from the half-way line to cement his side's 26-7 victory. That meant they went into the plate competition and faced Samoa who they beat to make the final against South Africa.
Rees added: "I am so proud of the boys and they all deserve the success because they have worked so hard."
The Sevens final was contested between England and New Zealand and in a classic encounter it was the All Blacks who won the final to take gold. Wales's conquerers in the quarter-finals Fiji, beat hosts Australia 24-17 to take the bronze medal while Kenya beat Tonga 26-12 to win the bowl.