Day 3, Stumps South Africa 220 and 187 for 4 (Markram 74, van der Dussen 64, Yasir 3-53) lead Pakistan 378 (Fawad 109, Ashraf 64, Rabada 3-70, Maharaj 3-90) by 29 runs

There may have been some angst about the quality of this Karachi pitch two days ago, but if this is the sort of Test match it produces, few could complain. South Africa began the day with their backs to the wall and Pakistan squeezed them ever further in the first hour, storming ahead to a 158-run lead. At that stage, an innings defeat looked more likely than a South African recovery, but innings of Job-like patience from Aiden Markram and Rassie van der Dussen saw them claw ahead half an hour before the close of play.

The game would turn around in an instant though, with three devastatingly quick strikes from Pakistan, who got rid of Markram, van der Dussen and Faf du Plessis to perhaps close out the day in as impregnable a position as they began it. South Africa finished just 29 runs ahead with four wickets down, but it looked so much better when van der Dussen and Markram got together for a partnership of 127 runs stretched across 51 overs.

Pakistan had begun to worry until those twilight strikes. Despite them being well in control at tea, South Africa had made relatively light work of the hosts' sizeable lead. Runs had begun flowing off the bats of both set batsmen, who started scoring at above four an over in the final session en route to their half-centuries. And once South Africa breached the 158-run mark, each run took on further more importance for Pakistan, with the knowledge that they would have to gun down every one of those in the fourth innings on an untrustworthy pitch weighing heavily on them.

Hasan Ali managed to reverse swing the ball, but both batsmen still found the gaps effectively. Though van der Dussen never looked as confident as his runs he scores suggest, after starting extremely cautiously, the shackles had come off as his partnership with Markram extended.

Markram, who until today had managed just 109 runs in Asia in nine innings, was batting with the same gravitas that had helped him take Test cricket by storm three years ago, looking well on his way to a first century in the format since 2018.

It was a fairy tale day for South Africa until that point, but the epilogue contained the cruelest of twists. Yasir Shah, who had toiled all day without achieving the wickets his performance merited, finally prised van der Dussen out, an exceptionally silly mid-off clinging onto a slightly uppish defensive prod from the batsman to break a superb three hours of resistance.

One brought two - and then three for Pakistan - when du Plessis, who never looked comfortable during his short stay, was trapped in front, before Nauman Ali struck the most telling blow. Markram was the man who then followed to the dressing room, with some extra bounce from Nauman hitting the top of his bat to spoon a catch to Abid Ali at silly mid-off, the batsman flailing his hand in disgust as he trudged off the pitch.

South Africa had begun day three just as despondently as they had capped a dismal second day, allowing Pakistan's tail to not so much wag as hop, skip and jump all the way to a potentially decisive lead. A 55-run partnership for the tenth wicket drove a stake deeper through the heart of the visitors' chances in this Test as Pakistan wrapped up with 378 on the board, ensuring South Africa would have to fight hard just to make them bat again.

Shah's innings may have looked casual with the ever-present smile on his face and the caution he threw to the wind along the way, but this was no laughing matter for South Africa's bowlers. After Pakistan began the day eight wickets down and 88 ahead, South Africa knew every run they added would tilt the odds further against them. They started off well enough when Kagiso Rabada knocked out Hasan's middle stump in the second over of the day to reach to become the third-fastest to 200 Test wickets.

But there was little time to celebrate, especially as Nauman and Shah decided they still fancied a bat. The former crunched Rabada for four the first ball he bowled, while soon after, Shah drove him through the covers before perfectly placing a square cut for another boundary in the same over. Pakistan brought up 350, with their lead touching 150 when Shah danced down the ground to deposit Keshav Maharaj over long-on for six.

The left-arm spinner did finally snare Nauman but not before Pakistan's advantage had increased up to 158, as South Africa had an hour to negotiate before lunch. But the one thing they drew comfort from was Dean Elgar and Markram neutralising the new ball, which lay in the hands of Shaheen Afridi and Hasan.

But if the morning session was a bit liberal in allowing the rate at which runs were scored, the afternoon session spent all its time overcompensating. Two hours of grind later, the sides still remained locked into the same situation they found themselves in at lunch, with Pakistan still on top. The visitors lost only Elgar, but posted just 55 runs in a session that at one juncture had seen them manage just four runs across eight overs.

Shah carried the greatest threat to the batsmen all day, and might at times feel he could have had more than just the one wicket if van der Dussen and Markram hadn't shut up shop against him completely. He found turn from the rough from around the wicket, but with lbw taken out of the equation, the pair were content to pad him away whenever the chance came.

But while Shah was responsible for Elgar's wicket, it came only after Afridi had crunched him on the little finger with a nasty rearing delivery that required elongated treatment from the physio. It looked at one stage as if Elgar might come off the field temporarily, but Shah - and a brilliant catch from Mohammad Rizwan - would ensure it was permanent. Elgar tried to sweep and the ball scooped up off the glove, with Rizwan completing a diving catch forward that ended with him in the middle of the pitch.

Scans later revealed Elgar was fine, but even as that bit of good news was filtering through, South Africa were enduring that fateful final half hour that may yet punish them following a spirited fightback. With batting getting steadily harder, they will hope there's more life in the pitch, because if so, there's life left in the visitors yet.

Danyal Rasool is a sub-editor at ESPNcricinfo. @Danny61000