Late wickets cost Pakistan as they dropped to 291-6 against Sri Lanka on day three of the third Test in Sharjah, a first innings deficit of 137 runs.
Ahmed Shehzad scored his maiden Test century to boost Pakistan, but the loss of three wickets late in the day has left them in peril.
With a 1-0 lead in the three-match series, Sri Lanka need only to draw to triumph and they batted cautiously on their way to 428-9 declared on Friday.
Pakistan responded in kind but the wicket of Shehzad for 147 was one of three in the last hour as Sri Lanka regained the upper hand.
Shehzad and Khurram Manzoor survived six overs on Friday 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-2.
The second wicket to fall was that of Azhar Ali, who perished for just eight, edging Dilruwan Perera to slip fielder Angelo Mathews.
Shehzad reached three figures in the fourth over after tea with a two off Kaushal Perera from the 230th ball he faced. He celebrated by hitting his eighth boundary two balls later.
Younis 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 was 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 was dismissed in the last over for five as Herath ended the day with 3-88.