DUNEDIN, New Zealand (AP) — Ross Taylor batted through a painful leg injury to make a valiant 181 not out and guide New Zealand to a five-wicket win over England in the fourth one-day cricket international Wednesday, leveling the five-match series at 2-2.

England seemed to have achieved an insurmountable total when it reached 335-9, batting first after losing the toss, with centuries to Jonny Bairstow (138) and Joe Root (102).

Taylor came to the crease with New Zealand having lost openers Martin Guptill and Colin Munro, both without scoring.

The veteran right-hander — who turns 34 on Thursday — missed the third match of the series with a left leg strain and aggravated the existing problem when he dived during his innings Wednesday to avoid a runout.

Limping and often grimacing in pain, with his troubles made worse at times by cramping, Taylor reached the 19th century of his one-day international career, surpassed his highest score of 131 and steered New Zealand to 339-5 with three balls to spare.

Taylor first added 84 with captain Kane Williamson (45) for the third wicket, then put on 187 for the fourth wicket with Tom Latham (71) with whom he scored 179 to lift New Zealand to victory in the first match of the series at Hamilton.

Taylor took his 181 runs from 147 balls with 17 fours and six sixes, gradually making the impossible look possible. After his two major partnerships he also worked up important late stands of 30 with Colin de Grandhomme (23 from 12 balls) for the fifth wicket and 36 with Henry Nicholls (13 not out) who hit six runs from the third ball of the final over, bowled by Tom Curran, for the winnings runs.

The final match of the series is in Christchurch on Saturday.

With Taylor's help, New Zealand managed to avoid the fate of England, who lost 5-59 in the last 10 overs, to fall short of the total that seemed likely when they were 267-2 on Bairstow's dismissal in the 38th over.

"It was nice to be there at the end," Taylor said. "We knew chasing that total that we just had to give ourselves a chance. It was a good wicket, we needed to just set those little goals along the way and give ourselves a chance. You never win a game like that in the first 10 overs but you certainly do lose it."

New Zealand needed 37 from the last 36 balls, having finally knocked their target down to a run a ball. England then exerted itself and shut down the run flow for more than an over, tipping the balance of the match in its favor.

Taylor hit a six off Woakes in the 48th over, then New Zealand reached the 49th over needing 13 from 12 balls.

It needed three from the last over: the first two balls bowled by Tom Curran yielded no run, but Nicholls hit the third for six into the midst of an excited crowd to end the game.

Earlier, Bairstow and Root were on target for a record score when the pair were together at 267-1 in the 38th over. But Bairstow's dismissal by part-time medium-pacer Colin Munro, from whom he had just previously hit a six over the gabled grandstand at the University Oval, precipitated a collapse which saw England lose 6-19 in 6.1 overs.

Root batted on, powerless as a series of partners departed, to reach his 11th ODI century from 99 balls before being dismissed in the 48th over, at which stage England had lost 7-28. England stumbled to 305-8 before Root was out and had seemed to have given up some of advantage but a late, unbeaten 22 by Curran, who hit four fours from the last over bowled by Tim Southee, put the tourists back on top.

Leg-spinner Ish Sodhi led New Zealand's comeback, taking 4-58, including Ben Stokes for 1.