Hafeez scored 63 and Akmal contributed 64, the pair putting on 102 for the third wicket to lead Pakistan to a total of 176 for four.
South Africa, who won the first game of the two-match series in a rain-affected encounter on Wednesday, managed only 170 for four in reply, with opener Hashim Amla hitting 48 and JP Duminy adding 47 not out.
The teams start a three-match series of one-dayers at Newlands on Sunday.
Image: Pakistan captain Mohammad Hafeez and Ahmed Shehzad celebrate after beating South Africa on Friday
Photograph: Shaun Roy/Gallo Images/Getty Images
South Africa secure narrow win over Pakistan after rain
Pakistan paceman Irfan ruled out of South Africa tour
South Africa's De Kock, Steyn seal Pakistan ODI series
Pacers give South Africa big win over Pakistan
'My best memory of Tendulkar was when we won the 2011 World Cup'