At lunch Pakistan were 198-4 with Misbah unbeaten on 60 and Shafiq 67 not out, with the two having so far added 128 for the unbroken fifth wicket stand at Dubai Stadium.
Pakistan still need another 220 to avoid an innings defeat.
The day began with the news that South African player Faf du Plessis had been fined 50 percent of his match fee on ball tampering charges by match referee David Boon of Australia.
Boon held a hearing later Friday during which Du Plessis pleaded guilty, becoming the first South African punished for ball tampering in international cricket.
More From This Section
On the field, Misbah and Shafiq added injury to South Africa's insult by batting with a resolve to fight hard.
South Africa, seeking a series-levelling win, tried valiantly to dislodge the two batsmen and even got a reprieve when Shafiq was adjudged leg-before off paceman Vernon Philander in the fifth over of the day.
Shafiq, who scored 54 in Pakistan's seven-wicket win in last week's first Test in Abu Dhabi, reached his ninth Test fifty when he guided Jean-Paul Duminy towards third man. It took him 121 balls, with his knock featuring four boundaries and a six.
Misbah followed Shafiq, reaching his 22nd half-century in Test cricket with a single towards third man off paceman Morne Morkel. He also took 121 balls and hit three fours and six.