Pakistan opening batsman Ahmed Shehzad struck his maiden Test century, only for late scalps to give Sri Lanka command of the third Test.
With a 1-0 lead in the three-match rubber, Sri Lanka need only to draw at Sharjah to seal a series win and they batted cautiously on their way to 428 for nine declared.
Pakistan responded in kind and closed on 291 for six, the wicket of Shehzad for 147 one of three to fall in the last hour.
Shehzad and Khurram Manzoor survived six overs yesterday evening and went on to put together a century stand for the first wicket.
Manzoor fell for 52, caught down the leg side by wicketkeeper Prasanna Jayawardene off paceman Shaminda Eranga and having no luck with a review, but Shehzad stood firm and was 92 not out by tea, with Pakistan 169 for two.
The second wicket to fall was that of Azhar Ali, who edged Dilruwan Perera to Angelo Mathews at slip.
Shehzad reached three figures in the fourth over after tea with a two off Perera from the 230th ball he faced.
Younus Khan fell for 17, Jayawardene taking another good leg-side catch to give Rangana Herath his first wicket.
Shehzad began to accelerate, hitting Eranga for four and six and adding three more boundaries in quick succession, but was bizarrely dismissed when a reverse-sweep at Herath came off the bottom edge and trickled into the stumps.
Asad Shafiq fell lbw to Eranga for 18, playing across the line, with the decision upheld on review.
Misbah-ul-Haq was 36 not out, including a late six off Herath, but Sarfraz Ahmed departed in the last over for five as Herath ended the day with 3-88.