England was cruising at 232-4 in the 37th over in pursuit of South Africa's 256-7 at the Wanderers when Joe Denly's dismissal for 66 sparked the late collapse. Moeen Ali saw England home with 17 not out from 16 balls in his first international in six months.
England finished on 257-8 with nearly seven overs to spare for a victory that wasn't as comfortable as it should have been. England also took a share of the series, its first one-day outing since winning the Cricket World Cup last year.
South Africa won the first game of this series and the second was abandoned because of rain. Denly made his second half-century of the series and was once again the mainstay of the England innings at No. 5. He hit six fours and three sixes and followed on from opener Jonny Bairstow, who made 43, and Joe Root, who scored 49.
With England needing just 25 runs with six wickets and plenty of overs in hand, Denly was caught at deep cover to kick off England's scrambling finish. Tom Banton (32) went three balls later and Tom Curran (5) the over after that. England was eight wickets down when Adil Rashid edged behind to give fast bowler Lungi Ngidi his third wicket.
Ali drilled one through the covers for four on the first ball of the next over and then got the one run needed for the victory. South Africa's sub-par total after being put in to bat by England was partly due to legspinner Rashid, who was also recalled alongside Ali for his first appearance this tour.
He took 3-51, including the crucial wickets of South Africa captain Quinton de Kock for 69 and No. 3 Temba Bavuma for 29. David Miller hit 69 not out for South Africa at the end of the innings but it wasn't enough.
Pace bowler Saqib Mahmood made a promising ODI debut for England with 1-17 off five overs. Rashid was also denied a wicket in bizarre circumstances after he thought he had got Rassie van der Dussen for a first-ball duck. Van der Dussen was given out lbw and, thinking that South Africa had just used its one decision review, walked off. Van der Dussen was then informed by umpires he could review the decision, which he did, and it showed the ball was missing the stumps. He was hovering near the boundary at the time but walked all the way back to the crease.
The farce began one ball before with the dismissal of Bavuma, also given out lbw to Rashid. Bavuma reviewed but part of the technology — the UltraEdge, which shows if the bat made contact with the ball — wasn't working. Even though there wasn't enough evidence to overturn Bavuma's dismissal, South Africa was given its one review for the innings back because of the malfunction.
Van der Dussen's reprieve against Rashid didn't matter much. Ali bowled him for five soon after.
More AP sports: https://apnews.com/apf-sports and https://twitter.com/AP_Sports