Mahela Jayawardene led Sri Lanka's revival with an unbeaten half-century on day two of the second Test against Pakistan in Colombo.
Jayawardene enabled the home side to stabilise with a battling 72 not out and was well assisted by Angelo Mathews (31), with whom he put on 71 runs for the fifth wicket.
But Pakistan chipped away at the Sri Lanka line-up with the hosts reaching 164 for five at the tea interval, still 135 runs adrift of Pakistan's first innings total. Chaminda Vaas, on one, was the batsman at the other end.
Fast bowler Thilan Thushara made short work of the Pakistan tail in the morning, finishing with a five-wicket haul as the visitors were bowled out for 299, their last six wickets yielding just 14 runs.
But off-spinner Saeed Ajmal brought Pakistan back into contention with two wickets as Sri Lanka were reduced to 82 for four in the afternoon session.
Ajmal and leg-spinner Danish Kaneria both put Jayawardene and Mathews under pressure, but the two survived to help Sri Lanka recover.
Kaneria broke the stand just before the tea interval by dismissing Mathews and, with Tillakaratne Dilshan being unable to bat due to a finger injury, Sri Lanka were left with a backs-to-the-wall battle.
In the morning, Thushara and fellow fast bowler Nuwan Kulasekara had claimed the three remaining Pakistan wickets within the first 17 minutes of play, ending Pakistan's first innings one run short of the 300 mark.
Thushara finished with figures of five for 83 from 24.4 overs, while Kulasekara claimed three for 47.
Sri Lanka's reply began poorly with Umar Gul bowling opener Malinda Warnapura off the first ball of the innings.
Warnapura had attempted to drive across the line and missed as Gul's delivery pegged back off stump.
Pakistan captain Younus Khan then replaced Gul after three overs from the fast bowler and snared Tharanga Paranavitana (five) with his medium pace.
Younus had generated plenty of seam movement and rattled the stumps with one that nipped back sharply from outside off stump as the batsman shouldered arms.
The advantage could have been greater for Pakistan had Khurram Manzoor held on to a catch offered by Sangakkara while on 16.
The batsman had pushed at a short-pitched delivery and had edged to Manzoor at gully, but the fielder grassed what should have been a comfortable catch.
Ajmal, however, earned a doubtful leg-before decision from umpire Ian Gould to send back the batsman on the stroke of lunch.
Ajmal's delivery had pitched a shade outside leg stump and spun in, striking Sangakkara just below the knee roll as he attempted to sweep. Gould, after much consideration, upheld the appeal.
The home side then lost Thilan Samaraweera almost immediately after the lunch interval.
Samaraweera had begun confidently and had produced a couple of sublime drives but Ajmal got one to spin back sharply from outside off stump and uproot middle stump.
Mathews, who was dropped on 12 by wicketkeeper Kamran Akmal off Ajmal, had begun aggressively, clubbing a couple of boundaries early on and taking the fight to the opposition.
But Kaneria ended his resistance just before tea, dropping a delivery slightly short and producing the edge as Mathews reached for it. Misbah-ul Haq completed a simple catch at slip.