Sri Lanka's former captain Kumar Sangakkara fell just short of another test double century but thwarted Pakistan's hopes of victory as the second test ended in a draw on Wednesday.
Sangakkara was dismissed for 192 in the hosts' first innings but shared in a crucial 92-run sixth-wicket partnership with Angelo Mathews (47) as Sri Lanka passed the follow-on mark before being dismissed for 391 just after lunch.
Pakistan then set Sri Lanka a daunting victory target of 261 from a minimum of 37 overs after their second turn at bat was closed two overs after tea at 100-2.
The hosts ambled to 86 for two from 22 overs before captains Mahela Jayawardene and Misbah ul-Haq agreed to a draw. Sri Lanka lead the three-test series 1-0.
Pakistan left-arm fast bowler Junaid Khan was named man of the match for his five-wicket haul in Sri Lanka's first innings.
Sangakkara, who narrowly missed out on a double century in the first test when he was out for 199 in Galle, resumed at the start of the day with his side tenuously poised at 278-5 and still requiring 74 more runs to make Pakistan bat again.
The tourists, who took the second new ball towards the end of the fourth day, had hoped for an early breakthrough from Khan, who snapped up two late wickets on Tuesday.
However, Sangakkara and Mathews safely negotiated the early overs to frustrate Pakistan, who tried everything to break the stand on a docile wicket.
Sangakkara moved past 150 for the 16th time in tests and at the lunch interval had blasted 15 fours and one six in an innings spanning more than eight hours.
Mathews also hit one six in addition to four boundaries in his 101-ball knock and while his departure sparked a lower order collapse as Sri Lanka lost their last five wickets for 21 runs in 43 balls, by that stage any hope Pakistan had of winning the match had been extinguished.
Khan, who had troubled all the Sri Lanka batsmen with his accurate bowling, picked up the wickets of Mathews and Nuwan Kulasekara (0) to finish with figures of five for 73, the second five-wicket haul of his career.
Left-arm spinner Abdur Rehman took the other three wickets after lunch to finish with four for 78.
He captured the prize wicket of Sangakkara when the left-hander mistimed a shot off his legs to offer up an easy catch to Taufiq Umar at square leg.
Sangakkara had batted for 511 minutes and faced 351 balls. Rehman also accounted for Prasanna Jayawardene (6) and Nuwan Pradeep (1).
Pakistan who scored a mammoth 551-6 declared in their first innings, batted for just 12 balls after tea before ending their second turn at bat. Taufiq Umar was unbeaten on 42 and Adnan Akmal on nought.
Off-spinner Suraj Randiv had earlier dismissed Mohammad Hafeez (21) and Abdur Rehman (36).
Randiv had Hafeez caught by Tillakaratne Dilshan at square leg and then bowled Rehman in the final over before tea.
In the ultimately fruitless chase, Sri Lanka lost their two openers, Dilshan (28) and Tharanga Paranavitana (32), to Rehman and fellow spinner Saeed Ajmal respectively.
Sangakkara was unbeaten on 24 and captain Mahela Jayawardene on one when the match ended predictably in a stalemate.