The tourists’ pursuit of 257 started superbly with a 23-ball 43 from Jonny Bairstow and looked set to be completed with ease when Denly, who hit 87 in a losing cause in the first ODI, made 66 and shared in healthy partnerships with Joe Root (49) and Tom Banton (32).
However, having been 232-4 midway through the 37th over, England lost a flurry of wickets at the back end of their innings before Moeen Ali hit the winning runs with 40 balls to spare.
In the annual ‘Pink ODI’, Moeen and fellow recalled spinner Rashid had earlier impressed with the ball to limit South Africa to a modest total of 256-7.
Moeen, representing England for the first time since last year’s Ashes, returned 1-42 from 10 economical overs, while Rashid was the pick of the attack with 3-51.
Home skipper Quinton de Kock and David Miller each made 69, the latter finishing unbeaten after some much-needed late acceleration, but South Africa’s score appeared insufficient and that ultimately proved the case.
Bairstow looked in superb touch early on, the opener taking 20 off a Lungi Ngidi over and also dishing out heavy punishment to Beuran Hendricks in a brief innings that featured six fours and three maximums.
A series of tame dismissals, including Bairstow’s exit at the hands of Lutho Sipamla, undermined England’s progress but they were soon back on track as Denly and Root put on 76 for the fourth wicket.
Denly did receive a let-off on 23 when a leaping Ngidi tried to take a boundary catch off Andile Phehlukwayo and succeeded only in tipping the ball over the rope for six.
England’s number five was otherwise assured, though, and he continued to prosper alongside Banton after the similarly impressive Root had been superbly caught at leg slip by Temba Bavuma off Tabraiz Shamsi.
It was therefore a surprise when wickets tumbled late on, but South Africa’s fightback came too late in the day.
The hosts’ innings featured a memorable moment for England debutant Saqib Mahmood, who bowled opener Reeza Hendricks for 11 with a wonderful delivery that clipped the off bail.
A bizarre controversy followed, with the UltraEdge technology unavailable due to a technical error when Bavuma (29) unsuccessfully reviewed an lbw verdict that had gone in favour of Rashid.
The malfunction meant South Africa retained their review, handing a surprise reprieve to Rassie van der Dussen, who initially walked off after being trapped in front by Rashid only to be stopped just inside the boundary rope before the decision was overturned.
Van der Dussen failed to capitalise, however, as he was bowled by Moeen in the next over. De Kock and Miller made healthy contributions – the latter finding his range at the death as Chris Jordan toiled – but it was not enough.
Get breaking news alerts.
You have already subscribed