Azhar Ali kept Pakistan afloat with a fighting unbeaten 85 as Sri Lanka tightened their grip on the second Test at the P. Sara Oval in Colombo on Sunday.
Pakistan, who trailed by 177 runs after the first innings, lost two important second innings wickets in the morning session as they took their overnight score of 171-2 to 244-4 by lunch on the fourth day.
Azhar closed in on his ninth Test century, helping Pakistan to wipe off the deficit and gain a lead of 67 runs with six wickets in hand.
Asad Shafiq was the other batsman at the crease on 10 with the tourists needing to build on the total to deny Sri Lanka a series-levelling win.
Pakistan won the first Test in Galle by 10 wickets to take the lead in the three-match series.
Azhar added four runs to his overnight score of 64 when he was dropped by a diving Kumar Sangakkara at first slip off seamer Dhammika Prasad, a catch that wicketkeeper Dinesh Chandimal could have attempted.
But Sri Lanka secured a crucial wicket soon after when Younis Khan edged an outswinger from Angelo Mathews to Chandimal, ending a 73-run stand for the third wicket with Azhar.
Younis, who had hoped for a big knock in his 100th Test appearance, scored 40 after making six in the first innings.
Skipper Misbah-ul Haq, seemingly disturbed by a band playing in the stands, requested the umpires to stop the music since it upset his concentration.
The band obliged, but Misbah did not last long at the crease as he was trapped leg-before by Prasad for 22.
The third and final Test begins in Pallekele on July 3. (AFP)