England's challenge is to win their next seven matches - a sequence they managed last summer - in order to both beat South Africa and then win their first global ODI tournament.
Stokes is a vital part of England's plans to win the Champions Trophy and secure their first major global 50-over title.
When De Kock got a faint edge behind off Moeen the pressure was right back on South Africa's chase.
On a day of six dropped catches by South Africa, it was Stokes who made them pay most heavily with his second one-day worldwide hundred, along with Jos Buttler's 46-ball 50 and telling runs too from Eoin Morgan.
England looked out of ideas but Plunkett returned and, seemingly from nowhere, found a delivery to oust De Villiers, the ball flicking off his glove and through to Buttler.
However, Mark Wood's (0-48) excellent death bowling limited them to four runs in the last six balls to ensure the finale at Lord's will be a dead rubber.
Miller then took 10 from the first two balls of Jake Ball's over to put South Africa on the brink of victory.
Jos Buttler eased himself into the innings, while Stokes took charge.
Earlier, Morgan's 107 - his 10th ODI hundred for England - was the cornerstone of the host's total of 339 for six. Amla eventually went leaning back on a thrashed drive in the covers off Stokes that flew straight to Morgan.
De Villiers, who made a sparkling 52 at better than a run-a-ball, gloved a well-directed short delivery from fast bowler Liam Plunkett (three for 64) through to wicket-keeper Buttler. South Africa, on the other hand, have little time to put behind the loss and make a comeback to keep the series alive.
De Kock hit 11 boundaries in a measured 103-ball knock but was denied a ton when he tickled Moeen (1-59) behind.