Ultra-cautious batting by opener Tharanga Paranavitana and former captain Kumar Sangakkara in fading light edged Sri Lanka back into the second Test against Pakistan on Friday.
The pair ended the day on 88 for 1 in the second innings.
Sri Lanka still trail Pakistan by 76 runs, but should thank Paranavitana (42 not out) and Sangakkara (29 not out) for staving off the opponents' attack after the fall of Lahiru Thirimanne for eight, when the score was 22.
Beginning their second innings 164 runs behind, after two days on the back foot, Paranavitana nurdled his runs off 141 deliveries while the usually fluent Sangakkara compiled his watchful innings from 86 balls.
Thirimanne was bowled by an excellent Mohammad Hafeez delivery that turned and clipped the left-hander's off-stump, after which the unbeaten duo put on 66.
Having resumed on 281 for four, Pakistan, who are playing 'home' Tests in the Gulf region because of security fears in their own country, were all out for 403 in their first innings.
Left-arm paceman Chanaka Welegedara dismissed two batsmen early in the morning to peg back Pakistan before the spinners cleaned up the rest later on.
He struck in the second over of the first session, luring Pakistan captain Misbah-ul Haq (41) to edge a loose drive into the hands of a tumbling Mahela Jayawardene at second slip.
Night-watchman Saeed Ajmal (20), who was dropped by Angelo Mathews off Welegedara on 14, frustrated Sri Lanka during a 41-run stand with Asad Shafiq for the sixth wicket.
Mathews made amends when a second edge from Ajmal flew to him at gully off the same bowler.
Shafiq (59) and wicketkeeper-batsman Adnan Akmal (41) added 70 for the seventh wicket to build on Pakistan's lead at the Dubai International Stadium.
Shafiq then edged Dhammika Prasad to Jayawardene in the slips for the paceman's third wicket of the innings and it paved the way for the spinners to force a mini collapse.
Left-arm spinner Rangana Herath struck twice in an over and captain Tillakaratne Dilshan picked his third wicket as Pakistan lost four wickets in less than an hour after lunch.
The first Test in Abu Dhabi was drawn, while the third and final match will be played in Sharjah from November 3.
Scorecard
Sri Lanka (1st innings): 239
Pakistan (1st innings): (overnight 281-4)
M. Hafeez lbw b Prasad 33
T. Umar c Silva b Prasad 27
A. Ali lbw b Dilshan 100
Y. Khan b Dilshan 55
Misbah-ul Haq c Jayawardene b Welegedara 41
S. Ajmal c Mathews b Welegedara 20
A. Shafiq c Jayawardene b Prasad 59
A. Akmal c Silva b Dilshan 41
A. Rehman b Herath 0
U. Gul lbw b Herath 2
J. Khan not out 0
Extras: (b-10, lb-10, w-2, nb-3) 25
Total: (all out; 141.1 overs) 403
Fall of wickets: 1-63, 2-64, 3-181, 4-275, 5-283, 6-324, 7-394, 8-397, 9-399, 10-403.
Bowling: Welegedara 29-7-79-2 (1w), Prasad 32-2-104-3 (3nb), Herath 37-5-89-2, Lakmal 24-8-54-0 (1w), Dilshan 19.1-1-57-3.
Sri Lanka (2nd innings):
T. Paranavitana not out 42
L. Thirimanne b Hafeez 8
K. Sangakkara not out 29
Extras: (b-6, lb-1, nb-2) 9
Total: (for one wicket, 45 overs) 88
Fall of wickets: 1-22
To bat: M. Jayawardene, T. Dilshan, A. Mathews, K. Silva, D. Prasad, R. Herath, C. Welegedara, S. Lakmal
Bowling: U. Gul 7-2-15-0 (1nb), Junaid Khan 6-0-14-0 (1nb), M. Hafeez 11-1-24-1, A. Rehman 13-2-20-0, S. Ajmal 8-4-8-0.
Sri Lanka retain Dilshan as captain
Supreme Court stays Ajmal Kasab's death sentence
Hockey 9s, learning experience for Indian eves: Kumar
Samaraweera, Welegedara steer SL to victory
Tharanga leads SL to big win over Aus