Off-spinner took the last three wickets in three balls as the hosts won by 239-runs at The Oval.
Moeen Ali hat-trick completes one-sided Test as England take series lead
Moeen Ali's hat-trick saw England complete a 239-run win over South Africa in the third Test at The Oval on Monday
Victory put England 2-1 up in this four-match series with just the fourth Test at Old Trafford starting Friday to come.
Off-spinner Ali ended the match when, after having Dean Elgar and Kagiso Rabada caught at first slip by Ben Stokes with the last two balls of his 16th over, had Morne Morkel lbw with the next.
Resuming on 117-4 after being set a huge target of 492 for victory, South Africa were dismissed for 252 on the final day of what was the 100th Test at The Oval.
Opening batsman Elgar, who made a gritty 136, got good support from Temba Bavuma (32) in a stand of 108 after South Africa had collapsed to 52-4 on Sunday.
But Toby Roland-Jones's dream England debut continued when the Middlesex paceman struck twice in two balls before lunch on Monday to dismiss Bavuma and Vernon Philander.
And when Chris Morris fell to the last ball before lunch, edging Ali to slip, South Africa were 205 for seven.
This was a memorable match for all-rounder Stokes, who made 112 in the hosts' first innings 353 and then took two wickets in two balls late on Sunday.
Roland-Jones returned figures of five for 57 in South Africa's meagre first innings 175, while fellow debutant Tom Westley made 59 in England's second innings 313 for eight declared.
* Agence France-Presse