The Scots have now lost top spot in Pool B to South Africa and must beat Samoa in their final game next weekend or risk losing out on a quarter-final place.
The Pacific Islanders' hopes of qualifying are now gone after losing to Japan.
South Africa opened the scoring, with Schalk Burger adding the finishing touch after a ruck of bodies crashed over the Scottish line
JP Pietersen added a second just before half-time after Scotland's vulnerability to the driven maul again shone through.
But the Scots stepped it up after the break, scoring a magnificent try through Tommy Seymour after stand-in stand-off Duncan Weir - replacing the injured Finn Russell - made a 80-yard intercept run.
They even closed to within six points and a losing bonus point before the Boks regained their composure, scoring a third try seven minutes from time as Bryan Habana dived over in the corner to seal a 34-16 win.