Kumar Sangakkara stroked a cautious unbeaten century as Sri Lanka made slow and steady progress in their bid to save the first Test against Pakistan in Abu Dhabi.
By stumps on day four, Sri Lanka had reached 298-5 in their second innings, still needing another 16 runs to make Pakistan bat again.
Starting out at 47-1, Sangakkara was at the crease all day moving his own personal tally on from 27 to 161 by the close.
So far he has faced 295 deliveries, struck 16 fours and shared in a 153-run partnership with Lahiru Thirimanne for the second wicket.
However, their 304-ball stand ended when Thirimanne was run out for 68.
Opener Thirimanne, who made a maiden Test fifty, was dismissed trying to complete a second run shortly after lunch, failing to beat Azhar Ali's throw from fine-leg.
The wicket offered Pakistan a chink of light and they grasped the moment by claiming two quickfire scalps - the first of which came when Saeed Ajmal got one to turn sharply from outside off stump before careering into Mahela Jayawardene's stumps.
Sangakkara reached three figures with a powerful cut off a wide Junaid Khan ball but he was soon battening down the hatches once more after Sri Lanka lost their fourth wicket when Junaid Khan got one to nip back through captain Tillakaratne Dilshan's defences.
Angelo Mathews, Sri Lanka's top scorer in the first innings, held out for 22 but Umar Gul snared him lbw from the first delivery with the second new ball.
Prasanna Jayawardene provided a calming influence through to stumps, being happy to rotate the strike in accumulating 25 not out before the close.
The opening session was a tale of woe for Pakistan. They dropped two straightforward catches and two more half-chances as Sri Lanka made it to lunch on 125-1.
Mohammad Hafeez at first slip was particularly profligate, dropping Thirimanne twice when the batsman was on 40 with left-armer Junaid the unlucky bowler on both occasions.
The first came from the final ball of the 27th over, Hafeez spilling a low chance to his left, and then from the next ball he faced Thirimanne was let off again when Hafeez failed to hold on after the ball went straight into his hands and popped out again.
Sangakkara also had his moments of fortune, surviving after the umpires decided an edge off the unfortunate Junaid did not carry.
Thirimanne had a third let-off on 57 with Hafeez again the fielder, spilling a more difficult chance in the gully after the batsman had flashed hard at an Ajmal delivery.
Hafeez got a taste of his own medicine shortly before lunch when he was bowling as Younus Khan, at full stretch, could only get a palm to an edge off the bat of Sangakkara.