Along with Tahir's triple, Dale Steyn, passed fit after a hamstring strain threatened his participation at the Dubai International Stadium, claimed two wickets as his importance to the Proteas was underlined.
The hosts had been making a cautious start but when three wickets fell with the score on 60 it put a different complexion on matters, as South Africa moved into the ascendancy.
Pakistan entered the game with a 1-0 lead in the two-Test series following a seven-wicket victory in the first Test in Abu Dhabi.
However, they made a poor start when Khurram Manzoor was out without a run on the board.
Manzoor went for a flamboyant cover drive from an outswinging ball from Steyn, getting a thick edge which flew to Faf du Plessis at gully.
Steyn was unleashing some deliveries reflecting his status as the world number one-ranked bowler, Shan Masood and Azhar Ali standing in the face of a ball coming at them at up to 140 kilometres an hour.
Pakistan were making patient progress and had reached 38 when Azhar Ali was out to Morne Morkel.
Morkel bowled a full length which Azhar came forward to play and replays showed the the ball would have clipped leg stump, the batsman out lbw for 19 off 54 deliveries.
Pakistan were then reduced to 52 for three when Masood was bowled by Tahir (three for 17) after making 21 off 60 deliveries.
After a cautious start Pakistan were wobbling and things went from bad to worse when they lost three wickets for no runs after reaching 60.
Younis Khan was first to go for 10 off a full delivery from Steyn which the batsman pushed lamely to AB de Villiers for a simple catch.
Tahir then claimed his second wicket three balls later when Misbah-ul-Haq was caught low on the pad to be lbw for just two, the decision vindicated by replays.
Tahir was on fire and three deliveries later he claimed his third wicket of the session when his full ball to Adnan Akmal clipped leg stump.
The batsman was out for a duck and had faced just three balls, lunch coming to Pakistan's rescue after a miserable first session.