Flawed strokemaking and inept umpiring combined to ramp up the tension before a Daniel Vettori-inspired New Zealand completed their greatest run chase on foreign soil to win their first cricket test against Bangladesh in Chittagong on Wednesday.

Set 317 for victory, New Zealand lurched across the line midway through a dramatic final session at the Divisional Stadium.

When Kyle Mills scampered the winning single to take New Zealand to 317 for seven it represented their highest successful fourth innings run chase overseas in their 343-test history — eclipsing the 164 for four made at Perth’s WACA ground to clinch the 1985 series against Australia.

New Zealand had the luxury of five sessions and 154 overs to reach their goal but they still required a massive input from Vettori to avoid becoming the first major cricketing nation to lose to the sub continent’s so-called minnows.

Vettori was immense, providing the epitome of a captain’s knock as he practically denied Bangladesh a coveted second test triumph singlehandedly.

Not content with taking nine wickets and top scoring with a face-saving 55 in New Zealand’s meagre first innings, Vettori surpassed those achievements by marshalling the pursuit expertly after arriving at the crease with a tricky 172 runs still required.

The skipper, who astutely employed himself as nightwatchman three overs before stumps last night after Jesse Ryder ran himself out, marshalled New Zealand’s painstaking pursuit with a resolute 76, the first time he has scored a fifty in both innings of a test.

Vettori, 0 not out overnight, remained steadfast from the first ball of day five, until he was bowled by Abdur Razzak when attempting tired a slog sweep.

That initially left Daniel Flynn and Jacob Oram to tick off the last 19 runs — an assignment not without its jitters.

The allrounder could have been run out when scampering to get off the mark and Flynn was then denied a maiden test 50 when he was caught bat pad a run shy when the scores were tied.

Vettori’s sterling service was not spoiled though, and deservedly so.

He faced 217 balls and struck seven boundaries in between long periods of staunch defence.

The left hander added 40 with opener Aaron Redmond and a soothing 82 with Flynn for the sixth wicket in difficult circumstances.

The 84-cap veteran and four-test rookie united when Bangladesh sensed a momentum shift after New Zealand lost Redmond, Ross Taylor and Brendon McCullum in the space of 31 runs.

But Vettori and Flynn maintained their composure in the face of a sequence of ear-splitting Bangladeshi appeals that eventually drew a mild rebuke from Australian umpire Daryl Harper.

Bangladesh became more vocal either side of lunch, and understandably so after Taylor and McCullum fell in quick succession.

Taylor (9) had only himself to blame when he scooped a short pitched offering from Mashrafe Mortaza to substitute fielder Mahbubul Alam at point.

Then seven balls into the middle session Bangladesh had more cause for celebration when Sri Lanka umpire erred in giving McCullum out leg before wicket to Razzak for two despite the ball clearly pitching outside leg stump — criteria to find in favour of the batsman.

The aggressive McCullum’s unfortunate demise left New Zealand at an edgy 216 for five but Vettori took test rookie Flynn under his wing to good effect.

Accustomed to batting under challenging circumstances after debuting in England five months ago, Flynn proved the ideal companion for Vettori, adopting a patient approach before peeling consecutive fours to go to 17 and break a 145-ball drought without a boundary.

He persevered for 126 balls before left arm spinner Shakib Al Hasan stalled the victory celebrations momentarily.

Redmond set the circumspect tone from the top of the order on Tuesday with his maiden test fifty, knuckled down again on Wednesday.

He added 40 with Vettori while advancing from 62 to 79 before edging Al Hasan to Junaid Siddique to end an admirable resistance that spanned 237 balls, 10 of which crossed the boundary.

Al Hasan, who took seven for 36 in New Zealand’s first innings backed up with two for 80. Fellow left arm tweaker Razzak took three for 93 off a marathon 50 overs to no avail.