Pallekele - JP Duminy hit 97 and a fit-again Hashim Amla made 77 to lift South Africa to 238 all out in a must-win one-day international against Sri Lanka in Pallekele on Sunday.
But the Proteas, needing a win to level the five-match series 2-2, undid a good start by losing eight wickets for 87 runs after cruising at 118-1 in the 22nd over.
Duminy lashed seven boundaries and two sixes before he was last man out in the 49th over, bowled by unorthodox spinner Ajantha Mendis three runs short of a century.
Mendis finished with four for 51, while sling-arm fast bowler Lasith Malinga claimed three for 52 and Tillakaratne Dilshan took two wickets.
Amla, batting for the first time in the series after being injured while fielding in the only other game he played, anchored the start with a fluent half-century that contained nine boundaries.
Duminy shared a second-wicket stand of 101 with Amla after Quinton de Kock had been bowled by Malinga in the third over.
Dilshan removed Amla leg-before and had skipper AB de Villers caught behind by Kumar Sangakkara in the space of eight runs to make it 126-3 in the 25th over.
Faf du Plessis helped Duminy add 46 for the fourth wicket but his dismissal for 23, stumped off Rangana Herath, triggered a middle-order collapse.
Mendis bowled David Miller and had Farhaan Behardien caught at short-leg two balls later as South Africa slipped from 172-3 to 173-6.
Malinga returned to dismiss Robin Peterson (13) and Rory Kleinveldt (eight) before Mendis had Morne Morkel leg-before.
Sri Lanka: Angelo Mathews (capt), Tillakaratne Dilshan, Upul Tharanga, Kumar Sangakkara, Mahela Jayawardene, Dinesh Chandimal, Lahiru Thirimanne, Rangana Herath, Ajantha Mendis, Lasith Malinga, Thisara Perera.
South Africa: AB de Villiers (capt), Hashim Amla, Farhaan Behardien, Quinton de Kock, JP Duminy, Faf du Plessis, Rory Kleinveldt, David Miller, Morne Morkel, Robin Peterson, Lonwabo Tsotsobe.
Umpires: Ruchira Palliyaguruge (SRI) and Rod Tucker (AUS)
TV umpire: Richard Kettleborough (ENG)