With the test locked at 15-15, Liam Williams was forced to evade the wandering fan as the Welsh winger attempted to outsprint the cover defence into the corner.
Soon after the Springboks won a penalty, kicking for the corner and scoring the match-winning try through hooker Malcolm Marx to secure a 23-18 victory.
The try was the only five-pointer of the match, helping the World Cup holders come from behind to record their first victory in Cardiff in eight years.
Handre Pollard put over four penalties for South Africa, with a long range contribution from his own half by Frans Steyn and an additional three points on the final whistle for Elton Jantjies.
The 34-year-old Steyn, who came on early as injury substitute, was named man-of-the-match not only for his long range kicking but several exciting line breaks.
Wales led 12-9 at the halftime as South Africa struggled to get their mauls going and were poor with their box kicking while Wales look threatening on the few occasions they got ball out wide, especially to their explosive wingers Josh Adams and Louis Zammit Smith.
There was only a single scrum in the first half but South Africa won several penalties from setpieces in the second half as their forward power began to tell.
But they continue to give away penalties as Wales kept themselves in the lead with Biggar making it 18-15 in the 65th minute.
A minute before that, Wales had a one man advantage out wide with substitute Williams in a good position to score when the spectator ran onto the field and disrupted the promising move.
South Africa won a penalty in easy range to tie the game in the 72nd minute but gambled on kicking for a line out instead of seeking to level the score. It was from the lineout that Marx crashed over as the back of a driving maul that steamrolled the home defence to snatch victory near the end.