Pakistan are still 135 runs adrift of New Zealand's first innings total of 274 in which BJ Watling made a gutsy and vital 77 not out.
Azhar remains key for Pakistan if they are to build any kind of first innings lead.
The 33-year-old dropped anchor and found the boundary just four times as he crawled through to his 32nd Test half century. His 62 not out was carved painstakingly from 169 deliveries as the Pakistan scoring rate struggled to rise above two an over.
The equally-experienced Shafiq hit the same number of fours in his 26 which has so far occupied 85 balls.
- Farewell Hafeez -
The Pakistan top order was jolted by Boult's double strike either side of lunch.
Hafeez has been struggling for form for a while, having made just 66 runs in seven innings since scoring a hundred against Australia in Dubai in October, following his recall to the Test side after a two-year absence.
It was no surprise when Boult had him caught low down at second slip by Tim Southee for a fourth-ball duck in his first over, right before the lunch interval.
Hafeez, 38, who made his debut against Bangladesh in 2003, announced at the close of play that this Test, his 55th, would be his last.
"I feel time is up," said Hafeez who has scored 3644 runs, with 10 hundreds and 12 half centuries.
In the fourth full over after the break, Imam-ul-Haq took his eye off a Trent bouncer and was hit on the back of the helmet. Next ball, he edged to Southee at third slip and was on his way for just nine.
Azhar then dug in with Haris Sohail, adding 68 for the third wicket before Sohail edged Southee to Watling behind the stumps for 34.
It was Watling, with an unbeaten 77, who carried New Zealand's overnight total from 229-7 and added an invaluable 45 runs over the last three wickets to frustrate Pakistan.
During his five-and-a-half-hour knock in his 56th Test Watling became the 14th New Zealander to pass 3,000 runs.
Watling, dropped on nine by Imam off Bilal Asif on Monday, and debutant Will Somerville extended their eighth wicket partnership to 45 before Bilal Asif took all three final wickets to finish with 5-65, his second five wicket haul in five Tests.
The 33-year-old playing his 56th Test, reached his 16th Test half-century. His 77 not out came from 199 balls in five hours and 32 minutes, and included four boundaries.
Leg-spinner Yasir Shah, in his 33rd Test, failed to add to his three wickets on Monday, leaving him two short of becoming the fastest man to reach 200 Test scalps.
The current record has stood for 82 years after Australia's Clarrie Grimmett reached 200 wickets in 36 Tests in 1936.
(This story has not been edited by Business Standard staff and is auto-generated from a syndicated feed.)