Sri Lanka skipper Angelo Mathews led by example, hitting an unbeaten 77 to help his team overcome a top order wobble and take a 291-run lead against Pakistan at the end of the third day's play in the third and final Test.
At 35-3, Sri Lanka looked in deep trouble but Mathews added 81 runs with Jehan Mubarak (35) for the fifth wicket to steady the innings.
He and Dinesh Chandimal (39 not out) then added 67 runs to stretch the lead before bad light forced early stumps with Sri Lanka in firm control of the series-deciding contest.
Inforgraphic: Who rules the world of sport?
Having claimed the last Pakistani wicket in the morning to bowl out the visitors for 215, Sri Lanka wobbled early in their second innings with Rahat Ali troubling their batsmen in a brilliant display of swing bowling.
The left-arm paceman first pegged back the off stump of Dimuth Karunaratne, a first-innings centurion, then repeated the feat against Lahiru Thirimanne to wreck the top order.
His new ball partner Ehsan Adil got in on the act when he coaxed an edge from Kaushal Silva to claim the other Sri Lanka wicket to fall in a stop-start morning session interrupted by several rain delays.
Upul Tharanga (48) looked the most fluent of the Sri Lankan batsmen, hitting six boundaries in his nearly run-a-ball knock as he counter-attacked with aggression.
In Pictures: Preserving cricket’s history in a Dubai backyard
The southpaw, however, fell short of his fifty with Azhar Ali taking a smart bat-pad catch at forward short leg off Yasir Shah.
Back in the test squad after nearly eight years, Mubarak joined his captain in rebuilding the innings but was dismissed for 35 by Shah, who claimed his 24th wicket in the series.
Earlier, Sarfraz Ahmed remained not out after a defiant 78 as Pakistan conceded a 63-run first innings deficit.
Sri Lanka 278 all out & 228-5 (Mathews 77*, Rahat 2-58)
Pakistan 215 all out (Sarfraz 78*, Pradeep 3-29)