Afridi, Irfan bowl Pakistan to series-levelling win
Afridi took 3-26 and Irfan finished with 3-53 as Pakistan defended a low total of 209 to square the five-match series at 1-1.
South Africa pulled off a sensational one-run win in the first match in Sharjah on Wednesday.
The remaining matches will be played in Abu Dhabi (November 6 and 8) and in Sharjah (November 11).
Saeed Ajmal (2-15) also shared the bowling spoils as South Africa were bowled out for 143 in 40.4 overs with Ryan McLaren top-scoring with 29 not out.
Pakistan skipper Misbah-ul Haq attacked with slow bowlers as early as the fifth over, introducing Mohammad Hafeez who dried up the runs after Colin Ingram fell for four in the second over of the innings.
Ajmal accounted for Graeme Smith (14), who was bowled off his legs with South Africa on 43.
Six balls later Jean-Paul Duminy, who struck three boundaries in his 25, fell in paceman Mohammad Irfan's second spell, caught in the slips.
When on 21, Duminy completed 3,000 one-day runs in his 106th match.
Afridi struck with his first ball, trapping Faf du Plessis for 12 and in his next over he had dangerman AB de Villiers caught behind for 10, leaving South Africa reeling at 73-5.
It became 83-6 when Hafeez caught David Miller, who had made 11, in front of the wicket with a sharp delivery.
McLaren and Wayne Parnell (21) put on 35 for the seventh wicket but it only delayed the inevitable as South Africa slumped to their second lowest total against Pakistan, behind the 101 they made in Sharjah in 2000.
For Pakistan, Ahmed Shehzad was the mainstay with an 85-ball 58. Hafeez (26), Afridi (26) and skipper Misbah (25) failed to capitalise on good starts as McLaren (4-34) and Morne Morkel (3-38) ran through the innings.
Shehzad had steadied the innings during a 48-run second wicket partnership with Hafeez and another 60 for the third wicket with Misbah before McLaren derailed the innings with a double strike.
Hafeez played on and was bowled in McLaren's first over. When he had made eight, Misbah completed 1,000 one-day runs in 2013, becoming the third batsman to achieve the milestone after Australia's George Bailey and India's Virat Kohli.
But Misbah perished in rather soft fashion, flicking McLaren straight into the hands of mid-wicket. He hit a boundary and a six off 44 balls.
Pakistan needed Shehzad to keep going but the opener too fell an over later, caught and bowled off leg-spinner Imran Tahir to leave Pakistan in danger at 117-4. Shehzad hit four boundaries off 85 balls.
Umar Amin (14) and Umar Akmal (18) took Pakistan to 148 and into the power-play but both fell at the same score, Umar hitting Morkel straight into the hands of point while Amin edged McLaren's slow delivery to wicket-keeper AB de Villiers.
Afridi hit four boundaries off 20 balls while Wahab Riaz hit two sixes in his 18 to help Pakistan cross the 200-mark.