Elgar scored a courageous and battling century in the Third Test but he had no answer here to a pinpoint inswinger that crashed into his pad.
Bairstow was 33 not out, having survived a contentious umpire review for a slip catch after initially being given out for just four. A turning delivery caught the outside edge of Cook as he nicked behind to Quinton de Kock for 46 runs off 103 balls after two and a half testing hours at the crease.
His most telling intercession, however, came midway through the evening session, when he returned in the 39th over to lively up what had been a meandering South Africa innings.
As with Roland-Jones, the Ashes may prove to be a sterner challenge for Westley, particularly against the extreme pace of Mitchell Starc and Pat Cummins, but this was an ideal way for the Essex man to start his Test career, and if he continues in this vein he could solve England's problem No. 3 position. It made one wonder why South Africa played a sick player but as skipper du Plessis said: "Vern's such a good player you'd nearly take him at 50 per cent".
But South Africa struck three times after lunch to keep the contest in the balance.More news: Prince Philip Is Officially Retired! The Royal Attends His Last Public Engagement
More news: Can Sprint nab the Charter Communications deal it is chasing?
More news: North Korea 'an unacceptable threat' to United States
Cook's resistance ended four short of 50, driving with unusual gusto at spinner Maharaj but insufficient application. Westley too didn't last long as De Kock took a stunning catch off Rabada to send the right-hander back to the hut.
A Root and Stokes partnership is always a threat for England and the pair were laying the foundations for a fruitful collaboration, putting on 43, before Olivier trapped the England skipper leg before. However, it was the return of Maharaj's spin that eventually did for the former England captain.
But while he dug in for tea, Malan self-combusted, waving loosely at Morkel and feeding Faf du Plessis at slip.
Morkel will resume on 18 not out on the third day. It was well wide of Hashim Amla at slip and De Kock, realizing his big error, sat down and covered his face with his glove.
Dawid Malan could be excused for the loss of his wickets at The Oval where he got a pearler in the first innings and was out as England threw the bat in the second innings.
Stokes had put on 43 alongside Root and did the heavy lifting in a stand of 65 as he and Jonny Bairstow battled the second new ball.
The only minor note of discord in England's day - at least where a hugely contented crowd was concerned - came when Bairstow missed out on what would have been a richly deserved and wildly acclaimed century.