The Mumbai-born Ajaz became only the third player in international cricket to take all wickets in an innings after England off-spinner Jim Laker and India leg-spinner Anil Kumble, but the tourists could not stop India from getting to 325.
In reply, New Zealand could bat only a little over two hours before being bundled out for 62 to concede a first-innings lead of 263.
India decided against enforcing the follow-on and then tightened the screws by reaching 69 for no loss in their second innings, stretching their overall lead to 332 runs at the close of the second day's play.
Cheteshwar Pujara opened the batting in place of Shubman Gill, who suffered a blow to his right elbow while fielding at close-in, and was unbeaten on 29 with Mayank Agarwal 38 not out.
On a pitch offering plenty of assistance to the spin bowlers, India's Mohammed Siraj, who was left out of the first Test in Kanpur, bowled with aggression and pace with the new ball to rattle the touring side.
The fast bowler sent back New Zealand's stand-in captain Tom Latham, Will Young and the experienced Ross Taylor to reduce them to 17-3 in his opening spell.
After Siraj's initial blast, the top-ranked test side's batters surrendered meekly to India's spinners.
Off-spinner Ravichandran Ashwin picked up four wickets for eight runs as the New Zealand innings folded in just 28.1 overs.
The hosts' first innings total was built on a stroke-filled 150 from opening batter Agarwal.
Resuming on 221 for four, India lost two early wickets to Ajaz but kept accumulating runs on the second day of the test at the ground overlooking the Arabian Sea.
In his first over of the day the 33-year-old Ajaz, whose family immigrated to New Zealand in 1996, dismissed Wriddhiman Saha to complete his third five-wicket haul in a test innings and then had Ashwin bowled on his next delivery.
All-rounder Axar denied Ajaz the hat-trick and then combined in a 67-run stand for the seventh wicket with Agarwal to keep India on course towards a sizeable total.
The right-handed Agarwal, who hit 17 fours and four sixes, reached 150 with a cut shot off Ajaz but was caught behind on the next delivery. Axar was dismissed for 52 after notching up his maiden test half-century.
Ajaz finished with figures of 10-119 and walked off to a standing ovation from the sparse crowd and the Indian dressing room.
The opening test in Kanpur ended in a thrilling draw, with New Zealand's last batting pair hanging on in the final session to deny India victory.