New Zealand's lower order couldn't capitalize on patient half-centuries from B.J. Watling (59) and Henry Nicholls' (55), losing its last six wickets for just 29 runs to get bowled out for 249. It gave New Zealand an overall lead of 175 runs after it conceded a slender 74-run first innings lead.
Watling and Nicholls defied Pakistan for nearly 51 overs and raised a 112-run fifth-wicket stand before Shah (5/110) claimed four wickets in three overs and Hasan (5/45) wrapped up the tail quickly.
Pakistan had to wait until the second new ball after tea to end a gritty century stand after both Watling and Nicholls denied them success in the second session.
Shah triggered the collapse when Nicholls was caught behind before Colin de Grandhomme (3) and Watling were both trapped lbw by the leg-spinner in his next over.
Neil Wagner was undone by Shah's sharp turning delivery that knocked back the left-hander's off stump before Hasan returned and dismissed Ish Sodhi (18) and Trent Boult inside three deliveries to wrap up the innings quickly.
Watling faced 145 balls and Nicholls negotiated 171 deliveries in their skillful display of batting against spinners and fast bowlers. The pair came together after Hasan struck twice before lunch with New Zealand just 34 runs ahead.
They batted resolutely throughout the middle session with Nicholls surviving an lbw appeal on 44 off Shah when Pakistan opted for an ultimately unsuccessfully television referral before the left-hander raised his fifty just before tea.
Watling completed his fifty soon after the interval with a crisp driven boundary to mid-wicket off Hasan before Shah returned and wrecked New Zealand's hopes of building a substantial lead.
Earlier, Hasan's twin blows in five deliveries toppled New Zealand's top order as Pakistan reduced the visitors to 108/4.
Watling survived the last over before lunch when he successfully reversed an lbw decision against him off Bilal Asif's offspin as the television replays showed the ball would have missed the leg stump.
Hasan used reverse swing with perfection by nipping Ross Taylor (19) plumb leg before wicket. Four balls later Jeet Raval's (46) resistance finally ended when he edged the right-arm fast bowler behind.
Left-handed Raval was aggressive against Shah when New Zealand resumed on 56-1 and quickly wiped off the first innings deficit.
Raval used his feet well against Shah by hitting three boundaries in the leg-spinner's first two overs. However, captain Sarfraz Ahmed persisted with Shah and the leg-spinner finally got the breakthrough.
Kane Williamson (37) added 10 to his overnight score of 27 before Shah bowled the New Zealand skipper off a delivery that moved enough and tipped the off stump bail to break the 86-run second wicket stand.
Taylor was also dominant against Shah by smashing three fours in the leg-spinner's one over that included two meticulous cuts and one over mid-wicket.
But Hasan's twin strikes in his fourth over of the day pegged back New Zealand's progress. Nicholls and Watling kept Pakistan at bay until Shah wrecked the lower order after tea.
(With AP Inputs)