Colombo:Wily leg-spinner Danish Kaneria grabbed 5-62 as Pakistan inched ahead of Sri Lanka on the second day of the third and final Test here on Tuesday.
Off-sinner Saeed Ajmal chipped in with 3-70 as Pakistan, bowled out for 299 in the first innings, hit back to dismiss Sri Lanka for 233 in the final session of an absorbing day's play.
The tourists were 16-1 in their second knock at stumps to take an overall lead of 82 runs with nine wickets in hand on a pitch aiding spin at the Sinhalese sports club.
Kaneria took his 13th five-wicket haul as the ball turned and bounced to claim 14 wickets on the second day after seven had fallen on the first.
Sri Lanka's left-arm spinner Rangana Herath bowled Khurram Manzoor in the day's final over to leave Fawad Alam unbeaten on 14 and skipper Younus Khan on zero.
Sri Lanka owe it to a fluent 79 from Mahela Jayawardene, a brave 44 from the twice injured Tillakaratne Dilshan and shoddy fielding by Pakistan to ensure the deficit was not threatening.
Sri Lanka were tottering at 181-8 when Dilshan stepped in to stem the rot with the tailenders despite a broken finger on his right hand that prevented him from keeping wicket in the morning.
Dilshan hit two sixes and as many boundaries and inspired the last two batsmen, Herath and Thilan Thushara, to add a further 52 runs.
Just before he was the last man to be dismissed, Dilshan suffered a bloody cut above the left eye as a ball from Ajmal crashed through the helmet, prompting immediate medical attention on the field.
Pakistan will consider themselves unlucky to see Dilshan conjure the rescue act as umpire Ian Gould turned down an appeal for a catch off Ajmal before the batsman had scored. Television replays indicated a clear edge off the bat.
The tourists, however, put down three comfortable catches to allow Sri Lanka to wriggle out of a tight corner.
Sri Lankan captain Kumar Sangakkara, who made 45, was dropped twice on 16 and 40, both times by Manzoor in the gully region off young left-arm fast bowler Mohammad Aamer.
Sangakkara put on 40 for the third wicket with Jayawardene after openers Malinda Warnapura and Tharanga Paranavitana were dismissed early to reduce Sri Lanka to 23-2.
All-rounder Angelo Mathews assisted in the rescue act with 31, adding a valuable 71 for the fifth wicket with Jayawardene before he was caught in the slips off Kaneria.
Mathews should have gone on 12 when he nicked Ajmal, but wicket-keeper Kamran Akmal failed to hold a low sharp catch.
Pakistan, who resumed at overnight score of 289-7, lost their last three wickets in 22 balls for addition of 10 runs.
Thushara finished with 5-83, his maiden five-wicket haul in seven Tests, while Nuwan Kulasekera claimed 3-47.