Sri Lanka captain Angelo Mathews batted through the fourth day to reach his second Test century and wrestle control away from Pakistan in their series opener at Abu Dhabi.
Pakistan had begun the day with some belief they could secure victory before stumps, but by the time light brought a premature end they were left bowed by Mathews' unbeaten 116.
Dinesh Chandimal was the only batsman to fall during the day, hooking at Junaid Khan for 89, and with Sri Lanka finishing on 420 for five - a lead of 241 runs - it is now the tourists who have the best shot at victory.
Pakistan's miserable day began even before play commenced after it was confirmed that wicketkeeper Adnal Akmal would miss the remainder of the three-Test series after fracturing his hand when taking the catch to dismiss Kaushal Silva from the final ball on the third day.
Younis Khan was therefore handed the wicketkeeper's gloves from the start on day four and he was left to watch on as Mathews, who hit 91 when Sri Lanka collapsed to 204 in the first innings, led his side away from danger alongside Chandimal.
Starting with a lead of just seven runs, and star batsmen Kumar Sangakkara and Mahela Jayawardene already back in the pavilion, the tourists needed the captain's knock that Mathews studiously provided.
The 26-year-old, whose only international century had come against Australia in 2011, first embarked on a 138-run stand alongside Chandimal that began to turn the tide against Pakistan.
The pair both reached their half-centuries in the morning session. Chandimal tickled the out-of-sorts Saeed Ajmal (none for 96) to fine leg to reach his 50 and in the same over Mathews launched the spinner over his head for six.
Their stand reached three figures in the afternoon session, but just as Chandimal looked set to reach a century of his own he gifted away his wicket.
A Junaid bouncer provoked an ill-advised hook shot that Rahat Ali held at deep fine leg.
It was, however, the only moment of joy for Pakistan as Mathews remained steadfast to reach his first century since taking over as captain last February.
The all-rounder turned Bilawal Bhatti away to leg for two shortly after tea to bring up the milestone from his 239th ball.
He remained until the close and with wicketkeeper Prasanna Jayawardene (48 not out) had combined in an unbeaten 96-run stand for the sixth wicket that had all but ended Pakistan hopes of victory.