AB de Villiers reached his century in stunning fashion in the last over as South Africa set Pakistan a victory target of 269 runs in the fifth and final one-day international in Sharjah.
Hashim Amla had already scored three in the first over when he was dismissed with the fifth ball as Mohammad Irfan's full delivery wrapped the opener on the pads and he was given out lbw.
The Proteas' other starting batsman Quinton de Kock added 34 runs before he also went lbw off the bowling of Saeed Ajmal.
JP Duminy was then gone for just two before Francois du Plessis fell four runs short of his half-century, struggling to 46 off 89 balls.
De Villiers steadied the ship and entered the final over on 97 after the wickets of David Miller (15), Ryan McLaren (27) and Robin Peterson (2) had fallen.
Wayne Parnell (8*) was on strike and hit a four and then three to bring De Villiers to the crease.
He hit a four to bring up his century before impressively finishing six, four, four to end on 115 not out from 102 balls.
South Africa have already wrapped up the five-game series, holding a 3-1 lead ahead of today's encounter.