Tries from Hallam Amos and debutant Tomos Williams helped Wales into a 14-3 lead at the break, but South Africa fought back strongly and Travis Ismaiel and Makazole Mapimpi scored to put them in the ascendancy.
However, replacement Robert du Preez gifted Wales the win when his clearance kick was charged down and the ball fell kindly to Elias.
The only other match to count towards the rankings over the last seven days came in the Asia Rugby Championship where Hong Kong beat Korea 39-5 to claim their maiden title.
As Asian champions, Hong Kong now progress to a home-and-away Asia/Oceania play-off with the Cook Islands for the right to enter the four-team RWC 2019 global repechage tournament in November.
Hong Kong remain in 22nd place in the rankings, having only been able to improve their rating by three-hundredths. Korea stay 31st.
Full Story via World Rugby