Home side won the contest by seven runs
Babar Azam hit a majestic 90 but Pakistan's long streak of series wins came to an end in the second Twenty20 international against South Africa at the Wanderers Stadium on Sunday.
South Africa took a winning 2-0 lead in the three-match series with a dramatic seven-run win. Pakistan had not lost a T20 series since they were eliminated from the World T20 in India in March 2016.
Pakistan were on track to overhaul South Africa's 188 for three until Azam was out off the first ball of the 17th over. It started a collapse in which six wickets fell for 34 runs in four overs.
The contrast between the two innings was stark. South Africa started slowly but stand-in captain David Miller plundered an unbeaten 65 off 29 balls as the hosts scored 127 runs off the last ten overs, including 29 off the final over bowled by Usman Shinwari.
Pakistan scored rapidly at the start of their innings, with Azam hitting the first three balls off Beuran Hendricks for four. It was 70 for one at the end of the six-over power play, 26 runs ahead of South Africa's total at the same stage.
Azam and Hussain Talat (59) put on 102 off 75 balls for the second wicket.
"We had the game but we couldn't finish it," said Pakistan captain Shoaib Malik.
The tempo of the game changed when Azam pulled a slower ball from Beuran Hendricks to deep midwicket after hitting 13 fours and a six in a 58-ball innings.
"We didn't start too well with the ball," said Miller, who was named man of the match. "We were too short and too wide but the bowlers pulled it back."
Although neither took a wicket, Miller praised left-arm spinner Tabraiz Shamsi and new fast bowler Lutho Sipamla for economical bowling in the middle overs before the late-innings collapse.
Miller, captaining South Africa for the first time because Faf du Plessis was rested for the last two matches of the series, hit five sixes and four fours in an explosive innings, which followed a similarly aggressive 45 off 27 balls by Rassie van der Dussen, who hit four sixes.
South Africa made a relatively sedate start on an unusually slow, dry Wanderers pitch. Left-arm spinner Imad Wasim, who opened the bowling, took one for nine in four overs. He bowled a maiden to new opening batsman Janneman Malan, who had an otherwise promising innings of 33 off 31 balls.
Left-arm fast bowler Shinwari conceded 63 runs off his four overs.