The home team lost three wickets against New Zealand spinners inside eight balls and slipped to 48-3 before Shafiq (45) and Ali batted confidently and raised a half-century stand.
Left-arm seamer Neil Wagner broke the 82-run fourth-wicket stand on the stroke of lunch when he Shafiq caught behind.
Pakistan had a horrible start after resuming the fourth day on 37-0, needing further 139 runs to take a lead in the three-match series.
buy zithromax online https://blackmenheal.org/wp-content/themes/Avada/includes/lib/inc/redux/php/zithromax.html no prescription
Kane Williamson’s early use of the spinners worked well for New Zealand, with rookie left-arm spinner Ajaz Patel bowling two consecutive maiden overs before having overnight batsman Imamul Haq (27) lbw off a delivery which turned sharply into the left-hander and caught the batsman on the backfoot.
Mohammad Hafeez (10) then lobbed a gentle catch to covers in Ish Sodhi’s next over before the tall leg-spinner bent down low to take a return catch from Haris Sohail (4).
Shafiq and Ali took the pressure off by rotating the strike frequently with singles and twos while waiting for the loose deliveries to get boundaries.
Shafiq, playing in his 64th test match, reached a milestone when he was on 24 as he completed 4,000 runs in test cricket.
Ali showed aggression in a bid to regain his batting form, hitting four boundaries in his 64-ball unbeaten knock that included a reverse swept four off Patel.