South Africa’s fly half Derrick Hougaard rescued them from defeat as the clock ticked down.
The Boks took an early 19-0 lead, Earl Rose claiming a hat-trick, but Wales fought back and tries from Lee Thomas, Richard Rees and Matthew Nutthall (2) against one for Sangoni Mxoli gave Wales a 26-24 advantage in the closing stages.
But Derick Hougaard hit a drop goal for the Boks and Thomas pushed an injury time 40m penalty wide.
Wales face England in their final pool match in Edinburgh on Saturday, whilst South Africa carry their 100% record into a clash with New Zealand.
Wales U21 26
Tries: Nutthall (2), Rees, Thomas
Cons: Thomas (3)
South Africa U21 27
Tries: Rose (3), Mxoli
Cons: Hougaard (2)
DG: Hougaard
Wales: R Williams, M Nutthall, G Evans, S Ireland, C Czekaj, N MacLeod, R Rees, J Yapp, K Crawford, C Griffiths, AW Jones, I Evans, R Dale, J Edwards, G Quinnell.
Replacements: I George, W Kay, J Mills, R Dale, J Ireland, M Jones, S Ireland.