Chasing 264 to win the match, South Africa fell two runs short of victory in a game that was reduced to 45 overs per side due to rain.
Pakistan lost the wickets of Akmal and Anwar Ali (7) in successive deliveries before they were bowled out for 263.
Dale Steyn claimed six wickets, while Ryan McLaren and Tahir claimed one each.
South Africa's chase took an early blow when Graeme Smith was caught behind by Umar Akmal for one. Quinton de Kock and Hashim Amla took the Proteas to 96-1 before the former was dismissed by Shahid Afridi for 47.
South Africa looked to be heading for victory but the quick dismissals of Amla (98) and JP Duminy (15) gave Pakistan hope.
Despite scoring four runs off the final ball South Africa fell just short of victory, giving Pakistan an unassailable 2-0 lead in the three-match series.