Mohammad Nawaz and debutant Zahid Mahmood starred as Pakistan held their nerve to a seal a 2-1 Twenty20 series win over South Africa despite the best efforts of David Miller and Tabraiz Shamsi.
The Proteas were rocking at 65-7 and thinking of the plane home, with the brilliant Zahid taking 3-40 and Nawaz 2-13 to leave the tourists in a spin in Lahore.
All-rounder Miller made it a contest by clubbing an electric 85 off just 45 deliveries to steer South Africa to 164-8.
Shamsi's outstanding 4-25 made things even more interesting but ultimately the poor showing from the top order told as Pakistan secured a four-wicket win with eight balls to spare.
South Africa started poorly as Mohammad Nawaz's ripper clipped off Reeza Hendrick's (2) thigh and from his next over more early turn saw JJ Smuts (1) sky one that Babar Azam pouched running back from the ring.
Pite van Biljon (16) struck Hasan Ali for three consecutive fours in the sixth over before trying for one too many and seeing the spinner find a huge gap.
Zahid then came to the fore, Heinrich Klaasen (0) top-edging to short fine leg and Janneman Malan trapped lbw, while Andile Phehlukwayo (0) survived a leg before appeal in the same over.
Phehlukwayo fell to Usman Qadir in the next over and Zahid had a third when Dwaine Pretorius (9) - star of the second T20 - had his middle stump torn up.
It was Miller time from there, though, as South Africa's dangerman single-handedly made it a contest - slapping seven sixes and five fours in a sensational knock.
Miller cleared the ropes a couple of times off Zahid in the 13th over, before unloading for four sixes from the final set off Faheem Ashraf to give Pakistan a genuine chase.
Pakistan were looking pretty serene with a 51-run opening stand between Mohammad Rizwan (42) and Haider Ali (15) but Shamsi's turner left the latter's technique exposed and the same man had the former trapped plumb lbw.
Things became even more tense with Shamsi accounting for Hussain Talat (5) and Asif Ali (7), with Babar's industrious 44 coming to an end between those dismissals.
Faheem fell for 10 as Pakistan's legs wobbled but Nawaz (18) and Hasan (20) steered the hosts over the line, the latter clubbing a six over midwicket to seal the series in style.