The experienced slow bowler Saeed Ajmal dismissed a well-set Mahela Jayawardene (47) with some extra spin and bounce and then baffled Dinesh Chandimal (11) with a doosra to reduce Sri Lanka to 166 for five at one stage.
Captain Angelo Mathews (24) and wicketkeeper Prasanna Jayawardene (28) held firm with an unbroken sixth-wicket stand of 54 runs to deny Pakistan any further success.
Ajmal was confident he had Prasanna out leg before and the umpire agreed too but the batsman reviewed the decision successfully as replays showed the ball was bouncing over the stumps.
Sri Lanka first innings
F Karunaratne c Khan Y b Rehman 34
J Silva c Ahmed b Talha 17
K Sangakkara c Manzoor b Kahn J 52
D Jayawardene c Ali b Ajmal 47
L Chandimal c Shafiq b Ajmal 11
A Mathews not out 24
H Jayawardene not out 28
Total: (5 wickets; 90 overs) 220
Fall of wickets: 1-31 2-65 3-125 4-159 5-166
Faced with some accurate bowling from Pakistan, Sri Lanka found scoring difficult on a slow and low pitch at the Sharjah stadium after Mathews opted to bat after winning the toss.
Mohammad Talha, playing only his second test, struck early to get rid of Kaushal Silva (17) while left-arm spinner Abdur Rehman dismissed Dimuth Karunaratne (34) immediately after lunch.
Kumar Sangakkara (52) added 60 for the third wicket with Mahela to steady Sri Lanka's ship but hit paceman Junaid Khan tamely to mid-wicket after completing his 44th Test fifty.
Sangakkara, on 15, was lucky to survive an appeal for a catch after replays showed that he had gloved a sweep shot off Rehman. Pakistan opted not to challenge the umpire's not out verdict.
Mahela looked in good control against the spinners before failing to negotiate a ball from Ajmal which turned and bounced sharply to take the edge and reach Azhar Ali at short leg.
Sri Lanka, who lead the three Test series 1-0, would have been in more trouble if Talha had managed to hold on to a return catch off Mathews with the batsman yet to open his account.