South Africa have narrowly avoided a World Cup scare by edging past Samoa 13-5 to progress to the quarter-finals with a 100% record.
The reigning champions went ahead early on thanks to a Bryan Habana try which Morne Steyn converted.
Further penalties from Steyn and his namesake Frans Steyn gave South Africa a 13-0 half-time lead.
The Samoans held firm in the second period and were rewarded with a try when George Stowers went over.
With 10 minutes left of the game Samoa were reduced to 14 men when Paul Williams was sent off for a punching incident.
South Africa advance to the quarter-final stage as Pool D winners and are likely to face Australia in the quarter-finals, if Ireland defeat Italy in the final game of the group stage on Sunday morning.
Samoa, meanwhile, are expected to finish third in Pool D if Wales defeat Fiji on Sunday.