Pakistani bowlers then took over, limiting South Africa to 292-10 while chasing 321 runs to win the one-day series. After seven years, Pakistan finally won an ODI series in South Africa.
Following his strong 193 in the previous match, Fakhar, 30, smashed 101 off 104. As Pakistan posted 320-7, his inning was driven by nine fours and three sixes, while his opening partner Imam-ul-Haq made 57 off 73 with the help of three fours.
Hasan Ali played a quickfire 11-ball 32 in his comeback match to give Pakistan a competitive score after they collapsed near the end.
Temba Bavuma, the South African captain, put the visitors in to bat first, announcing seven changes to the playing XI.
Pakistan got off to a confident start, with Fakhar and Imam putting on a 100-run stand at the top of the order. Imam scored his second fifty of the series, but was dismissed in the 22nd over by Maharaj as he attempted to increase the scoring pace.
Fakhar, on the other side, accelerated after scoring fifty points. In the centre, he was joined by skipper Babar, and the pair added 84 runs for the second wicket.
Fakhar completed his sixth ODI century but was dismissed by Maharaj when he attempted a leg-side curl. He had nine fours and three sixes in his 104-ball inning.
The Green Shirts’ run rate fell to under six as they lost four wickets between the 36th and 46th overs. They only managed to score 51 runs.
In his comeback match, former captain Sarfaraz Ahmed scored 13 with two fours, while Rizwan (2), Faheem Ashraf (1), and Mohammad Nawaz (4) struggled.
The predicted score was less than 300, but Hasan Ali made the difference. He hit an unbeaten 32 off 11 balls, including four sixes and a four, and Babar was just six runs shy of another century.
After Pakistan beat South Africa in 3rd ODI, the skipper Babar Azam, who will become the No. 1 ODI batsman, hit seven fours and three sixes.
Keshav Maharaj took three for 45 for South Africa, while part-time Aiden Markram claimed 2/48.
In response, South Africa received help from Janneman Malan, who made a strong argument for the hosts despite the fact that wickets were falling at the other end. With the aid of nine boundaries, the right-handed batsman scored 70 runs off 81 balls.
Kyle Verreynne (62) and Andile Phehlukwayo (54) worked together to score 108 runs, and they were on track to chase the mark at one point. Haris Rauf, on the other hand, struck in the 44th over, bringing Pakistan back into the contest.
Hasan then teamed up with Haris to give Pakistan another breakthrough, this time with Phehlukwayo departing for 54, leaving South Africa with a score of 251-7.
Pakistani bowlers finished off the defence in style, taking the last three wickets at regular intervals to give the visitors a convincing victory.
Mohammad Nawaz and Shaheen Shah Afridi each took three wickets, while Haris took two. Hasan and Usman Qadir each took a wicket.