Pakistan appeared set to build a huge lead before collapsing from 286-3 to lose their final seven wickets for the addition of just 62 runs.
That gave Pakistan a 74-run lead -- the same advantage they held in the first Test at the same venue before losing by four runs.
Yasir needs just one more wicket to become the fastest to 200 wickets, in his 33rd Test, a record currently held by Australian leg-spinner Clarrie Grimmett who reached the milestone in 36 Tests, 82 years ago.
Shafiq said Pakistan must limit New Zealand in their second innings after his side failed to chase down 176 in the first Test.
"It's always nice to bat with Azhar," said Shafiq.
"But it was disappointing that we couldn't get a big lead. It happens in cricket and you have to give credit to the bowlers.
"We need to get them out quickly tomorrow so that we don't need to chase a lot of runs."
Azhar and Shafiq put on 201 for the fourth wicket, but once they were dismissed only Sarfraz Ahmed (25) and Babar Azam (14) offered some resistance.
He took 210 balls to reach the three-figure mark, before being caught sweeping off Somerville, just before tea.
Shafiq brought up his 12th Test ton with a sharp single off Somerville before falling leg-before to Patel to a straight delivery.
Somerville then had Azam and Hasan Ali (nought) bowled and wrapped up the innings by getting Sarfraz caught at mid-wicket.
Earlier, Azhar and Shafiq frustrated New Zealand's search for early wickets as they took Pakistan to 224-3 at lunch.
New Zealand skipper Williamson took the second new ball in the 81st over with Pakistan comfortably placed at 213-3, but the bowlers struggled to extract much life from a flat pitch at the Sheikh Zayed Stadium.
Pakistan levelled the series with an innings and 16-run win in the second Test in Dubai.
(This story has not been edited by Business Standard staff and is auto-generated from a syndicated feed.)