The Proteas had started the day in dominant fashion, their much-vaunted seam attack reducing the tourists to 33 for four by the 17th over.
But former skipper Younis and Shafiq both showed better application than their top-order team-mates, both men hitting unbeaten half-centuries in a tea total of 133 for four.
Vernon Philander had Nasir Jamshed dropped by Faf du Plessis at gully but dismissed him for three with the very next delivery in the eighth over when AB de Villiers gathered a simple catch behind the stumps.
Mohammad Hafeez scored the first boundary of the day off the 58th ball and moved along to 17 by the time Dale Steyn sent him back with the first ball of his second spell. A testing line and a hint of away movement produced the edge and and Smith took a low catch at slip.
Azhar Ali aimed an airy drive at Morne Morkel and was caught behind for four and Morkel made it 33 for four just four balls later, spearing one at captain Misbah-ul-Haq's body and being rewarded with an awkward fend to Dean Elgar at short-leg.
Younus and Shafiq steadied the ship and the pair continued watchfully after the resumption, adding just 13 in the first 10 overs of the afternoon session - including Shafiq's first boundary.
Shafiq was dropped at square leg on 24 off Robin Peterson and he made the most of his life, striking four fours in the next five overs to overtake Younis.
It was the veteran who reached 50 first, though, first edging Morkel for four past the cordon and then flaying Peterson for the first six of the day.
Shafiq reached the mark in the last over before tea, nudging Peterson for two and at the break Younis was 54 not out from 141 balls, with Shafiq 50no from 21 fewer.