Umar Gul turned an unlikely hero with the bat as Pakistan survived a middle-order collapse to beat South Africa by two wickets in the Super Eights of the World Twenty20 on Friday.
Pakistan, chasing South Africa's modest 133-6, crashed to 76-7 in the 15th over before Gul and Umar Akmal combined to share a match-winning partnership of 49 in 27 balls.
Gul smashed two fours and three sixes in his 32 off 17 balls before he was dismissed off the last ball of the 19th over by fast bowler Dale Steyn with nine more needed.
But Akmal, who remained unbeaten on 43, and Saeed Ajmal steered Pakistan home with two balls to spare, Ajmal edging the winning boundary off Morne Morkel.
"We were lucky to get there," said Pakistan captain Mohammad Hafeez. "There were a few bad shots early in the innings but in the end it was a great team effort.
"I knew Gul could play big shots and the good thing is that everyone in the team is contributing. The bowlers did well to keep South Africa to a low score."
South African skipper AB de Villiers said he was proud of the way the team fought back after batting badly.
"We probably lost it in the last five overs, but I am very proud the way we came back so strongly."
Pakistan's openers raced to 24 in 2.5 overs before the innings fell apart after Imran Nazir (14) was caught behind off Steyn.
Left-arm spinner Robin Peterson, who came to bowl the fourth over, removed Hafeez with his second delivery and Nasir Jamshed with the six to make Pakistan 31-3.
Off-spinner Johan Botha also struck in his first over by bowling Kamran Akmal for one, Jacques Kallis dismissed Shoaib Malik (12) and JP Duminy had danger man Shahid Afridi caught in the deep first ball.
But Gul and Umar Akmal launched a blistering attack on the Proteas to earn Pakistan full points in the opening match of group two.
India and Australia, the other two teams in the group, play in the second match of the double-header at the Premadasa stadium later on Friday night.
Earlier, Pakistan's spinners revelled on a slow wicket to restrict mighty South Africa to 133-6.
Hafeez claimed 2-23 and 20-year-old left-arm spinner Raza Hasan conceded just 12 runs in three overs after South Africa won the toss and elected to bat.
Seamers Yasir Arafat and Gul shared three wickets as the batsmen tried to hit out against them after failing to play the slow bowlers.
South Africa, the top-ranked side in the Twenty20 format, were reduced to 28-3 in 6.1 overs before recovering through de Villiers and JP Duminy.
Left-handed Duminy top-scored with 48 off 38 balls, while de Villiers made 25, but no other batsman reached 20.