Stuart Hogg became a Scotland record holder after a double against South Africa, but the world champions kicked their way to a 30-15 victory at BT Murrayfield.
Hogg scored two tries to take him up to 24 for Scotland and join Tony Stanger and Ian Smith at the top of the all-time list.
Gregor Townsend’s side matched the Springboks for tries, with Makazole Mapimpi also crossing twice and the hosts led 10-8 at half-time.
But the visitors’ control and physicality saw them comfortably win the penalty count and they kicked themselves out of sight in the final quarter of the Autumn Nations Series game.
Scotland were looking to follow up victory over Australia last Sunday and Townsend made four changes, with Glasgow winger Rufus McLean handed a start and Leicester centre Matt Scott starting his first international since June 2017. Hamish Watson had dropped to the bench.
Scotland faced a difficult opening, not helped by early handling errors from Finn Russell and Hogg, and they conceded five penalties in the opening 11 minutes.
They fronted up to the physicality of the tourists though and stole a line-out on their five-metre line, before Duhan Van Der Merwe turned defence into attack in devastating fashion after another turnover.
The South Africa-born winger ran from the try line to the halfway line before forcing a penalty which Russell kicked over from 40 metres after the visitors were further punished for dissent.
Russell soon missed another penalty from similar range but tougher angle and the home side were warned about the number of penalties they were conceding before Elton Jantjies kicked the visitors level.
Mapimpi went over in the 28th minute having evaded two despairing tackles after the visitors got an overload on the left wing.
Jantjies was well off target with the conversion and Scotland pushed forward before Hogg got his first try in the 34th minute following good possession. Russell kick out wide to Van Der Merwe for the second time in a minute and there were a series of offloads from the winger, Sam Skinner and Chris Harris before Hogg went over.
Russell converted but missed a good penalty chance to extend the half-time lead – seconds after visiting head coach Jacques Nienaber made three front-row substitutions rather than wait for half-time.
Nienaber also swapped scrum-halves at half-time and his side stepped up a gear.
Van Der Merwe was robbed in the air and Mapimpi soon went over inside three minutes of the restart following a good burst of pace and a perfectly timed pass from Damian De Allende.
Jantjies kicked the conversion plus two penalties before Hogg burst over again in the 59th minute. Scotland moved the ball quickly from left to right after a line-out and Van Der Merwe’s one-handed offload sent the captain running into yards of space to cross.
Russell missed the conversion to leave the deficit at six, but Scotland soon forced a penalty deep in visiting territory following a kick and chase.
However, South Africa stole the resulting line-out and the world champions turned the screw in the final quarter.
Their physicality forced a number of penalties which proved the difference. Handre Pollard kicked two and Frans Steyn added one from long range to secure an ultimately comfortable away win.