However, late in the day, South Africa lost the well-set Markram and van der Dussen, along with Faf du Plessis, to leave them in trouble.
Pakistan struggled for most of the day, but the first hour belonged to the home side, thanks to a last-wicket partnership of 55 between Yasir Shah and Nauman Ali.
They came together after Hasan Ali had his stumps uprooted by Kagiso Rabada for his 200th Test scalp - he became the third-quickest South African to the mark, in his 44th Test.
Pakistan were bowled out for 378 eventually. Shah ended on an unbeaten 37-ball 38*, and his brief cameo had seemingly pushed Pakistan into a position of dominance.
South African batsmen started the second innings in style and made their intentions clear.
They negated the second hour of the first session carefully to go into Lunch on 37/0, and despite the fall of Dean Elgar (29) shortly into the second session, the visitors managed to avoid the slide.
During the second session, the South Africans displayed grit and application. Makram was supported by van der Dussen, and the duo completed the first task of batting through the rest of the session without losing a wicket, going through to Tea at 84/1.
In the final session, they ensured they didn’t get bogged down either, putting away the loose deliveries whenever they could to slowly eat away at the deficit.
They batted together for the most part of the final session, and were on track to see through the day, with Pakistan’s bowlers struggling and failing. However, in his final burst, Yasir proved to be unplayable.
He first had van der Dussen flummoxed by a slower ball that dipped. He then trapped du Plessis plumb in front for 10, before the killer blow was struck by the debutant Nauman, who did Markram with extra bounce. (UNI)