England 330 for 5 (Stokes 101, Buttler 65*, Morgan 45) beat South Africa 328 for 5 (de Kock 98, Miller 71*, de Villiers 52) by two runs
Scorecard and ball-by-ball details

England closed out a dramatic victory over the No. 1-ranked ODI side to take the three-match series with one to play and hammer home their credentials as Champions Trophy contenders. Ben Stokes was the catalyst with a 77-ball hundred - as well as a wicket from his fifth ball - and although 98 from Quinton de Kock helped keep South Africa in the chase, England's bowlers stayed on top of the scoring as the asking-rate rose.

David Miller looked to have guided South Africa to the brink of victory with 71 off 51, a six and a four off the first two balls of the penultimate over leaving them needing 10 from 10. But Jake Ball conceded just three from the next four deliveries before Mark Wood defended seven off a nerveless final over to seal a two-run win and extend England's winning run to eight ODIs in a row.

With AB de Villiers also contributing a half-century, South Africa were on course to pull off what would have been comfortably the highest successful chase on the ground. By the time they entered the last ten needing 93 with six wickets standing, Miller had found his groove and, alongside Chris Morris, South Africa's sixth-wicket pair added 62 in 6.3 overs - only for the boundaries to dry up at the crucial juncture.

Stokes' second ODI hundred had lifted England out of trouble and allowed them to post another impressive total after being put in to bat for the second match running. Dropped twice from his first two balls, Stokes paved the way for England's recovery, which was capped by Jos Buttler's explosive, unbeaten 65 from 53. Stokes then took a wicket almost immediately after coming on to bowl but ended up delivering only three overs, as questions about his fitness lingered.

South Africa had moved relatively comfortably to 56 without loss when Stokes struck. Having narrowly failed to hold on one-handed to a chance from his first ball given by de Kock, he made the breakthrough when Hashim Amla drove loosely to cover.

De Kock had almost fallen in similar fashion to his Headingley dismissal, top-edging a swipe across the line against Ball on 16, but this time it carried over the wicketkeeper and slip and ran away for four. Ball was in the side for Chris Woakes, who had experienced a tight quad after taking a four-wicket haul in England's victory in the first ODI, and South Africa targeted the least-experienced member of the attack to help keep up with a demanding asking rate of 6.6 an over.

Although Liam Plunkett picked up Faf du Plessis via a tickle to the keeper, de Kock was largely untroubled in moving to a run-a-ball half-century. He and de Villiers judiciously milked the bowling during the middle overs, putting on 96 before Plunkett struck again with a well-directed short ball that brushed the South Africa captain's glove as he tried to limbo underneath.

With de Kock closing in on a 13th ODI hundred - and what would have been his third against England from seven innings - he was drawn into a poke at Moeen Ali to be caught behind. Miller showed his power in Moeen's following over by lofting him casually over long-off and he progressed to a 34-ball fifty, scoring the majority of a 55-run stand with Farhaan Behardien, before Plunkett had the latter taken at mid-off.

As at Leeds, South Africa won an apparently useful toss and England were 80 for 3 in the 16th over before a 95-run stand between Stokes and Eoin Morgan helped even up the contest. Morgan was not as fluent as he was during his hundred in the first match, surviving a caught-and-bowled chance on 16 before edging a cut against Kagiso Rabada, but Stokes accelerated after reaching his half-century, adding his second fifty from 29 deliveries to record a first hundred in home ODIs.

With the platform constructed, Buttler bent himself upon destruction during the latter stages. Buttler crashed his first ODI fifty since the tour of Bangladesh last year, from 46 balls, during stands of 77 with Stokes and 78 with Moeen. The 46th over, bowled by Andile Phehlukwayo, went for 22 as 111 flowed from the last ten; only Rabada, who picked up 2 for 50, managed to go at less than a run a ball for South Africa.

South Africa's cause was not aided by dropping five catches - three of them off the bowling of Keshav Maharaj, the left-arm spinner playing his maiden ODI. In the penultimate over, Amla failed to even get a hand on a skied top edge from Moeen at fine leg, to cap a poor effort in the field.

Stokes, playing with strapping on his knee, was given a couple of early lives but quickly put his scratchy start behind him to turn in the sort of dominating innings that helped win him the IPL's MVP award earlier this month. Pretorius was swung crisply down the ground for a one-bounce four, then Phehlukwayo mowed over deep midwicket for six; when Morris returned, he was deposited into the Shane Warne Stand off an even more towering blow.

After a top-edge off Rabada flew high between keeper and slip, Stokes followed up with a dismissive thump back down the ground and a single to bring up his half-century from 48 balls. Morris was again struck into the crowd before Maharaj did eventually claim his man - and his maiden ODI wicket - when Stokes holed out having reached his hundred.

With overhead conditions providing just a touch of assistance for the seamers early on, England had struggled through the initial Powerplay. Jason Roy's indifferent form continued when he was bowled by Rabada for 8 and although Alex Hales and Joe Root assembled a half-century stand at more than a run a ball, two quick wickets further undermined England's prospects.

Pretorius, one of three changes from the South Africa XI beaten at Headingley, recovered to see Hales smartly held by de Kock, standing up to the wicket, and then had a hand in seeing off Root, who looked in good touch until he was run out backing up: Morgan's drive deflected on to the non-striker's stumps by the bowler in his follow-through. It could have been even better, had Pretorius clung on to a tough opportunity off Morgan.

By then, Maharaj had confirmed himself in the luckless debutant category. Rabada's drop of Hales at long-on did not cost South Africa too much (although it added six to Maharaj's figures) but de Villiers would have been as perturbed as his bowler to see Stokes put down from consecutive balls. Stokes' first delivery saw Maharaj draw a thick edge, only for Amla to miss it completely at slip; then de Kock could not hold a more difficult opportunity, again off the outside edge of the bat. Two moments of good fortune that Stokes ensured he and England would capitalise on.

Alan Gardner is an assistant editor at ESPNcricinfo. @alanroderick