Opening batsman Ahmed Shehzad struck his maiden Test hundred but Pakistan's hopes of a series-equalling victory looked distant on the third day of the third and final Test on Saturday.
Trailing 1-0 in the three-match series, Pakistan were 291 runs for six wickets at the close, still needing 137 runs to wipe off their first innings deficit.
Captain Misbah-ul-Haq (36) was unbeaten at the crease as wicketkeeper Sarfraz Ahmed (five) fell on the final delivery of the day to give left-arm spinner Rangana Herath his third wicket of the innings.
Resuming on their overnight score of 19 for no loss, Shehzad (147) and his opening partner Khurram Manzoor (52) made a watchful start and went unscathed in the morning session.
The pair added 114 runs for the first wicket before Manzoor was caught down the leg side off paceman Shaminda Eranga.
Number three batsman Azhar Ali (eight) became debutant Dilruwan Perera's first Test wicket when he edged the off-spinner to slip.
The 22-year-old Shehzad, however, kept his calm at the other end and kept accumulating runs.
The right-handed batsman added 40 for the third wicket with Younis Khan (17) before his senior partner was smartly caught by wicketkeeper Prasanna Jayawardene off Herath.
Shehzad drove Perera elegantly for a couple of runs to reach his maiden hundred in his third Test and celebrated the occasion in front of a sparse crowd with a leap.
Pakistan's scoring rate improved with the arrival of Misbah at the crease and once Shehzad started playing more freely after completing his century.
But Shehzad was out while looking for quick runs as he dragged on Herath to his stumps, attempting a reverse sweep shot off a wide delivery.
Sri Lanka, who won the second Test in Dubai after the first match in Abu Dhabi ended in a draw, dismissed Asad Shafiq (18) and Sarfraz cheaply before the close to take the upper hand.
Sri Lanka first innings 428-9 dec.
Pakistan first innings (overnight 19-0)
Khurram Manzoor c P. Jayawardene b Eranga 52
Ahmed Shehzad b Herath 147
Azhar Ali c Mathews b Perera 8
Younis Khan c P. Jayawardene b Herath 17
Misbah-ul-Haq not out 36
Asad Shafiq lbw b Eranga 18
Sarfraz Ahmed c P. Jayawardene b Herath 5
Extras (b-1, lb-6, nb-1) 8
Total (six wickets; 95.3 overs) 291
Fall of wickets: 1-114 2-149 3-189 4-245 5-274
Bowling (to date): Herath 31.3-8-88-3, Lakmal 21-4-57-0, Perera 17-1-71-1, Eranga 19-5-53-2 (1nb), Mathews 7-3-15-0
Image: Ahmed Shehzad
Photograph: Francois Nel/Getty Images