New Zealand's Neil Wagner (C, top) celebrates dismissing India's MS Dhoni (R) during the second innings on day four of the first international test cricket match at Eden Park in Auckland. REUTERS/Nigel Marple

Auckland - Neil Wagner was the toast of New Zealand as they pulled off a dramatic 40-run win over India in the first Test at Eden Park on Sunday.

Wagner, New Zealand's go-to man, twice turned the game with quick wickets to wrest control away from India.

On a riveting fourth day of the David and Goliath clash between the eighth-ranked New Zealand and second-ranked India, the outcome was settled in the final session when India lost their last five wickets for 96 runs.

India went into the session requiring 137 to reach their 407 target while New Zealand needed five wickets.

As the target narrowed and wickets fell, rival skippers Brendon McCullum and Mahendra Singh Dhoni were forced to rethink their strategies.

When the first over after tea saw the removal of Rohit Sharma for 19, India opted to go on all-out attack.

Dhoni and Ravindra Jadeja belted 54 in under seven overs before Trent Boult ended their slogfest.

Two balls after being lofted for six by Jadeja, Boult exacted revenge by tempting him into a similar stroke with Ish Sodhi placed at mid on for the catch. Jadeja departed having made 26 off 21 deliveries.

Zaheer Khan joined Dhoni in a 25-run stand forcing McCullum to spell his senior bowler Tim Southee to bring back Wagner who instantly broke the partnership to reduce India to 349-8.

With Dhoni left to try to get his side home, Wagner struck again bowling the Indian captain for 39 leaving Boult to end the innings when Ishant Sharma was caught behind for four.

The dismissal gave wicketkeeper BJ Watling his sixth catch of the innings and he equalled Brendon McCullum's record of nine for the match.

Wagner ended the innings with four for 62 while Southee and Boult took three apiece.

Earlier, in a day of see-sawing fortunes, India were cruising at lunch after resuming at 87-1 and getting through the morning session for the loss of only Cheteshwar Pujara (23) to be 180-2.

New Zealand regained control after lunch when Wagner produced his first magic spell, toiling with the old ball to remove Shikhar Dhawan and Virat Kohli who had eased their way to 222.

He had Kohli caught low down by wicketkeeper Watling for 67 before nicking Dhawan's glove to remove the opener for 115.

It was the second Test century for the 28-year-old Dhawan, a late bloomer who was not required for Test duty until early last year.

New Zealand were fortunate to claim their third wicket of the session when Boult rapped Ajinkya Rahane (18) on the pads with the first delivery of the new ball in the last over before tea.

Replays showed the in-swinger hit the bat first.