Jesse Kriel scored a 78th-minute try to seal a 42-28 victory for South Africa over Scotland in a thrilling Nations Championship match in Pretoria on Saturday.
World champions South Africa built a 14-point lead after 18 minutes. Scotland tied the game by half-time.
The Boks went ahead by 21 points after half-time, but Scotland came back again with two tries and secured a four-try bonus point.
Embrose Papier, Evan Roos, Elrigh Louw, Damian Willemse, Zach Porthen and Kriel scored a try each for South Africa at a vibrant Loftus Versfeld stadium,
Recalled fly-half Handre Pollard shrugged off recent poor club form to slot five conversions and replacement back Quan Horn kicked one before a 45,000 crowd.
Matt Fagerson, Kyle Rowe, Josh Bayliss and Ben White crossed the line for the never-say-die Scots. Star fly-half Finn Russell converted all four.
Victory kept South Africa top of the southern hemisphere standings after the second round, ahead of arch rivals New Zealand on points difference after both achieved two bonus-point victories.
"All credit to Scotland, they played unbelievably well. But I am proud of the guys, we stuck to our systems and finished well at the end," said Springboks captain Pieter-Steph du Toit.
"The system is so well prepared in this team -- each player who comes into the side knows exactly what to do.
"We made some mistakes and they saw some weaknesses in our defence. We need to improve on that," added the flanker, who was standing in as skipper for injured Siya Kolisi.
Scotland captain and centre Sione Tuipulotu said: "I am a little bit gutted. South Africa came out really hot but we were able to battle back.
"I thought the period after half-time hurt us. We had a lot of possession in their 22 and did not capitalise.
"I am very disappointed at the moment, but also proud of the group. We played a positive brand of rugby, but it was not good enough."
After soaking up early pressure, South Africa struck twice within three minutes through Papier, making an impressive first appearance since 2018, and Roos.
While South Africa were guilty of constant ill discipline, Scotland showed forward power and backline flair to draw level at 14-14 by half-time.
Fagerson, then Rowe scored and Russell converted both as the Scots sought a first ever win in South Africa after seven losses since 1960.
Replacement Springbok forward Ben-Jason Dixon was yellow-carded early in the second half, but the Scots failed to translate subsequent dominance into points.
After Dixon returned, the Springboks enjoyed an eight-minute purple patch with Louw, Willemse and Porthen crossing the tryline.
Pollard converted all three and the record four-time Rugby World Cup winners were sitting pretty with a 35-14 lead.
But Scotland refused to give in and Bayliss and White scored, Russell converted both and suddenly there were just seven points between the teams.
Scottish wing Kyle Steyn knocked on a Russell cross kick when he looked set to score, then Kriel raced clear to put the outcome beyond doubt.
dl/pb