South Africa secured top spot in Pool D with victory over a valiant Samoa side in a classic encounter in Auckland.
The Springboks led 13-0 courtesy of a Bryan Habana try, two kicks from Morne Steyn and one from namesake Frans.
But Samoa shook the defending champions to their boots after the break, George Stowers crossing for a try as an ageing South Africa side began to creak.
Even when Paul Williams was sent off, Samoa continued to throw caution to the wind, but South Africa held firm.
The Springboks' victory means Samoa's World Cup campaign is effectively over, unless Fiji score four tries and beat Wales by more than 39 points on Sunday, with Wales not scoring four tries themselves.
Wales only need a losing bonus point to confirm second place in the group, and Fiji would need to win by 85 points (scoring four tries in the process), in Hamilton to overtake both Wales and Samoa.
South Africa will now play the runners-up in Pool C, likely to be Australia, although that could change if Italy cause an upset against Ireland.
Assuming Wales progress, they will play the winners of Pool C, which will be Ireland so long as Declan Kidney's men beat Italy.
Peter de Villiers' South Africa, who narrowly defeated Wales in their World Cup opener, have conceded only 24 points in their four games, fewer than any other team.
And while the Springboks looked like an over-the-hill side at times during their 17-16 win over Wales and this pulsating victory over Samoa, their tactical nous, set-piece strength and defensive rigour means few would bet against them reaching a second successive final.
In a frantic opening, Springboks fly-half Morne Steyn saw an early drop-goal attempt drift past the right upright before Frans Steyn struck the bar with a penalty attempt from inside his own half.
However, Habana made South Africa's possession tell after eight minutes, crossing for a try in the left-hand corner after an extended stay in the Samoa half. Morne Steyn kicked the extras.
Spurred on by a partisan crowd at North Harbour Stadium, Samoa continued to put in the big hits, with Ospreys number eight Stowers involved in one almighty collision with Springboks hooker Bismark du Plessis.
Tempers flared when Samoa skipper Mahonri Schwalger received a slap from Jannie du Plessis at a ruck, and the South Africa prop was lucky not to receive a yellow card.
Shortly after, Frans Steyn nailed a long-range three-pointer from wide right on the halfway line before namesake Morne slotted a penalty from bang in front as Samoa came under pressure in the scrum.
The defending champions lived up to their reputation as a formidably functional side in the first half, defending robustly and kicking for goal at every opportunity - Frans Steyn nearly knocked over one penalty attempt from inside his own 10m line.
However, Samoa continued to probe for openings and their industry very nearly paid off on the stroke of half-time when scrum-half Kahn Fotuali'i burst down the short side and fed inside to Seilala Mapusua, only for the hulking centre to be hunted down.
And after 51 minutes the crowd was sent into raptures when Stowers burst over for a try following nice hands from Gloucester centre Eliota Fuimaono-Sapolu. Tusi Pisi missed the conversion to leave his side trailing by eight points.
A few minutes later, Frans Steyn missed a penalty attempt from the left touch-line before Samoa wing David Lemi went slashing through the South African defence and would have scored were it not for a fine tackle from full-back Pat Lambie.
South Africa hit back immediately, Bismarck du Plessis lunging for the line only to be held up short, before Frans Steyn coughed up the ball under the posts under some heavy tackling.
Lemi then went on a dart down the right before Fuimaono-Sapolu stepped his way through the rattled Springboks defence, the vital tackle coming from Pietersen.
Shortly after, the dazzling Gloucester centre very nearly unpicked the South Africa defence again before Schwalger reached for the line and lost the ball in contact, allowing the Springboks to clear their lines.
With 12 minutes remaining, Samoa full-back Williams was sent off for striking Springboks blind-side Heinrich Brussow following an altercation at a ruck. But two minutes later it was 14 against 14 when Springboks replacement hooker John Smit was sin-binned for a deliberate knock-on.
The final 10 minutes were a torrid, rollercoaster affair. First, Samoa replacement Joe Tekori went on a charge down the middle before Springboks substitute Jean de Villiers stole the ball and stepped his way through the Samoa defence.
Samoa kept coming, and the Springboks were tottering when the final whistle went. And while Samoa's World Cup is over, they can be tremendously proud of a performance that was full of physicality, ambition and skill.
South Africa: Lambie, Pietersen, Fourie, F. Steyn, Habana, M. Steyn, du Preez, Mtawarira, B. du Plessis, J. du Plessis, Rossouw, Matfield, Brussow, Burger, Spies.
Replacements: Hougaard for Habana (47), Steenkamp for Mtawarira (62), Smit for B. du Plessis (69), Alberts for Spies (61).
Not Used: van der Linde, Louw, de Villiers.
Sin bin: Smit (70).
Samoa: Williams, Lemi, Mapusua, Fuimaono-Sapolu, Tuilagi, T. Pisi, Fotuali'i, Taulafo, Schwalger, Johnston, Leo, Thompson, Tuifua, Fa'asavalu, Stowers.
Replacements: Mulipola for Taulafo (77), Avei for Schwalger (77), Perenise for Johnston (60), Tekori for Leo (60), Treviranus for Tuifua (73).
Not Used: Poluleuligaga, G. Pisi.
Sent off: Williams (70).
Ref: Nigel Owens (Wales).