Tharanga Paranavitana and Kumar Sangakkara both hit half centuries on Sunday as Sri Lanka extended their lead over Pakistan to 237 runs at the close of the fourth day and set up an intriguing finale in the third and final Test in Sharjah.
Earlier Sri Lanka paceman Chanaka Welegedara picked up his maiden five-wicket haul in Tests to help dismiss Pakistan for 340 in their first innings.
Pakistan's bowlers fought back but Sri Lanka opener Paravanita was still at the crease on 66 when bad light brought a premature end to the day's play with the hosts on 164 for five.
Resuming on their overnight score of 282 for six, Pakistan, who lead the three-match series 1-0, were bundled out for 340 on the stroke of lunch.
Trailing Sri Lanka by 131 runs after the third day, captain Misbah-ul-Haq (89) added 47 for the ninth wicket with Saeed Ajmal (12 not out) to significantly cut into the lead after Pakistan lost Abdur Rehman and Umar Gul early.
Left-arm spinner Rangana Herath chipped in with three wickets while off-spinner Suraj Randiv took the scalp of Misbah, who skied a sweep that allowed Tillakaratne Dilshan to take a running catch.
Misbah, who was dropped three times in the first hour of play, effectively shielded Ajmal from the Sri Lankan attack during their ninth-wicket stand and hit seven boundaries and a six to frustrate the visitors.
Sri Lanka's hopes of garnering quick runs were dampened when the hosts claimed an early wicket as paceman Umar Gul found Dilshan's edge with the new ball.
First-innings centurion Sangakkara and opener Paranavitana added 75 runs for second wicket before Sangakkara was caught by Asad Shafiq at point off the bowling of Mohammad Hafeez for 51.
Mahela Jayawardene was trapped lbw by Umar Gul for 20, before Saeed Ajmal gave Pakistan hope of snatching a very unlikely victory with the wickets of Angelo Matthews (13) and Kaushal Silva (0) in the space of five balls.
The Pakistan fightback was halted when the umpires took the players off for bad light, effectively ending the prospect of an overnight declaration and leaving a draw as the most likely outcome.
Pakistan, who won the second match of the series by nine wickets, are playing "home" Tests in the Gulf region due to security concerns in their own country.
Scorecard
Sri Lanka first innings 413
Pakistan first innings (overnight 282-6)
M. Hafeez c Jayawardene b Welegedara 6
T. Umar st Silva b Herath 19
A. Ali b Kulasekara 53
Y. Khan b Welegedara 122
Misbah-ul-Haq c Dilshan b Randiv 89
A. Shafiq c Silva b Welegedara 16
A. Akmal lbw b Herath 7
A. Rehman c Paranavitana b Welegedara 3
U. Gul c Mathews b Herath 5
S. Ajmal not out 12
J. Khan b Welegedara 0
Extras (lb-2, w-3, nb-3) 8
Total (all out, 138.2 overs) 340
Fall of wickets: 1-8, 2-35, 3-133, 4-233, 5-258, 6-277, 7-282, 8-289, 9-336
Bowling: Welegedara 35.2-10-87-5, Prasad 4-0-9-0, Kulasekara 25-7-65-1, Herath 42-14-85-3, Randiv 25-5-74-1, Dilshan 7-1-18-0
Sri Lanka second innings
T. Paranavitana not out 66
T. Dilshan c Hafeez b Gul 4
K. Sangakkara c Asad Shafiq b Mohammad Hafeez 51
M. Jayawardene lbw b Umar Gul 20
A. Mathews lbw b Saeed Ajmal 13
K. Silva lbw b Saeed Ajmal 0
K. Kulasekara not out 4
Extras (lb-4 nb-2) 6
Total (for five wickets; 53.4 overs) 164
Fall of wickets: 1-5, 2-80, 3-127, 4-155, 5-155
Bowling: Gul 12.4-1-35-2, J. Khan 5-3-9-0, A. Rehman 12-1-38-0, Hafeez 10-1-34-1, Ajmal 14-2-44-2.
Ajmal's four-wkt haul fails to check Sri Lanka's charge
Sri Lanka hit back to leave Test finely poised
Paranavitana, Sangakkara lead Sri Lanka fightback
Sangakkara ton gives Sri Lanka early ascendancy
Ajmal sets up Pakistan nine-wicket victory