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.
“It was a really good performance, especially after getting out for a low score, our bowlers did the job for us again,” said Pakistan skipper Misbah-ul Haq.
South African captain AB de Villiers admitted his team’s batting was a concern.
“We have a few issues in the batting and it’s up to us to turn it around. I’m very disappointed. Pakistan were too good for us.”
Misbah 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 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.
Brief scores: Pakistan 209 in 49.4 overs (Ahmed Shehzad 58; R. McLaren 4-34, M. Morkel 3-38); South Africa 143 in 40.4 overs (R. McLaren 29 not out, Shahid Afridi 3-26, Mohammad Irfan 3-53).
Teams: Pakistan: Misbah-ul-Haq (capt), Ahmed Shehzad, Mohammad Hafeez, Mohammad Irfan, Nasir Jamshed, Saeed Ajmal, Shahid Afridi, Sohail Tanvir, Umar Akmal, Umar Amin, Wahab Riaz
South Africa: AB de Villiers (capt), Coiln Ingram, Jean-Paul Duminy, Faf du Plessis, Imran Tahir, Ryan McLaren, David Miller, Morne Morkel, Wayne Parnell, Graeme Smith, Lonwabo Tsotsobe
Umpires: Steve Davis (AUS) and Shozab Raza (PAK) TV umpire: Richard Illingworth (ENG) Match referee: Ranjan Madugalle (SRI)