Riaz grabbed 3-10 to derail Sri Lanka's second innings -- 34-5 at close -- but the visitors were still in a strong position with an overall lead of 254 runs with five wickets intact.
Riaz dismissed Sri Lankan skipper Dinesh Chandimal leg before for nought in the last over before close to give Pakistan a faint hope of upsetting the tables, but it will be an uphill task for their faltering batsmen to improve in the second innings.
Pakistan were dismissed for 262 in their first innings, conceding a big 220-run lead following Sri Lanka's first innings 482.
It was paceman Mohammad Abbas who started the slide, having opener Kaushal Silva caught behind for three before Riaz dismissed first innings centurion Dimuth Karunaratne for seven.
He then had debutant Sadeera Samarawickrama out for 13 in a hostile spell of 3.3 overs. Leg-spinner Yasir Shah had nightwatchman Suranga Lakmal out for one as Pakistan started to stage a fightback.
At close Kusal Mendis was unbeaten on eight.
Sri Lankan spinners Dilruwan Perera (3-72) and Rangana Herath (3-84) had bundled Pakistan out just after dinner to put Sri Lanka in sight of a series win.
They won the first Test by 21 runs in Abu Dhabi.
Only Azhar Ali (59) and Haris Sohail (56) offered some resistance as the Pakistani batsmen once again flopped on a batting friendly Dubai Stadium pitch, losing their last six wickets for 82 runs.
It was 21 runs short of the follow-on mark but Sri Lanka did not enforce it.
Ali and Sohail lifted Pakistan from a precarious 109-4 during a battling fifth-wicket stand of 71, but once Ali was gone the innings unfolded.
Herath trapped Ali leg-before and reviewed it to overturn a not-out decision, triggering the collapse. Ali hit six boundaries in his patient knock.
Sohail was the eighth wicket to fall, trapped in front by Perera to end any hopes of Pakistan reaching a respectable total. He smashed four boundaries and two sixes.
Skipper Sarfraz Ahmed made 14 before he miscued a sweep and was caught off Perera.
When Pakistan resumed at 51-0, paceman Lahiru Gamage who took his first wicket in Test cricket, bowling Shan Masood through the gate after the opener had made 16.
Sami Aslam was trapped leg before by Perera for 39 to leave Pakistan two down with 65 runs on the board.
Asad Shafiq fell for 12 when he edged Lakmal to slip to continue his wretched form in the series. Babar Azam made eight.
Lakmal finished with 2-41 while Gamage had figures of 2-38.
First Published: October 8, 2017, 11:55 PM IST