Angelo Mathews helped himself to a hundred for Sri Lanka as they moved into a 241-run lead against Pakistan in the first Test in Abu Dhabi.
Day four firmly belonged to Sri Lanka as they lost one wicket after moving from 186-4 to 420-5 at stumps, with Mathews finishing up on 116 not out.
Dinesh Chandimal was the only man out on Friday as Mathews passed his ton while Prasanna Jayawardene ended the day two runs short of his half-century.
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.
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 other Test century came 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 (0-96) to fine leg to reach his 50 and in the same over Mathews launched the spinner back 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 Khan bouncer provoked an ill-advised hook shot that Rahat Ali held at fine leg.
It was, however, the only moment of joy for Pakistan as Mathews remained steadfast to reach his first ton 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 the 239th ball he had faced.
He remained until the close and with wicketkeeper Prasanna Jayawardene (48no) combined in an unbeaten 96-run stand for the sixth wicket that had all but ended Pakistan hopes of victory.