Riaz, who had a morning spell of nine overs for 3-15, finished with 4-66 and Shah grabbed 4-93 as England were bowled out for 242 after resuming the day on a well-placed 182-3.
Pakistan had made 378 in their first innings.
Riaz initiated the collapse in which England lost their seven remaining wickets for 60 runs as he bowled with venom and guile to dismiss a dangerous looking Joe Root (88), Ben Stokes (four) and Jos Butler (nought) in an incisive spell.
Shah dismissed Adil Rashid (nought) and Jonny Bairstow in one over and Mark Wood (one) while fast bowler Imran Khan had James Anderson (four) to finish with 2-33.
England had hoped their batting would rally around the fast-rising Root who added two boundaries off Shah in the fourth over of the day to his overnight score of 76.
But Riaz found the edge of Root’s bat with a sharp outswinger to give Pakistan the much-needed breakthrough. Root smashed 12 boundaries during his 141-ball knock.
This spell from Wahab Riaz is gold.Could be match defining.#highquality
— Ashwin Ravichandran (@ashwinravi99) October 24, 2015
Bairstow survived some close calls and was surprisingly given not out by television umpire Chris Gaffaney of New Zealand when replays showed Younis Khan had taken the edge off Shah in the first slip.
Bairstow, then on 40, managed six more before Shah trapped him in front of the wicket, leaving England reeling at 223-8.
In between, Riaz had Stokes and Butler caught behind in successive overs.
The first of three Tests ended in a draw in Abu Dhabi last week.