Abid Ali and Shan Masood negotiated a tricky final hour as Pakistan wiped out the bulk of their first-innings deficit without losing a wicket on day two of the second Test in Karachi.

After collapsing to 191 all out in their first innings, Pakistan responded well through Shaheen Afridi (5-77) and Mohammad Abbas (4-55) on Friday, but Dinesh Chandimal's 74 lifted Sri Lanka to 271 and a lead of 80.

Pakistan openers Abid and Masood then reached 57 without loss from 14 overs before bad light brought play to a close, leaving the contest intriguingly poised.

The day had started brightly for Pakistan, with both Afridi – who took his first five-for in Tests – and Abbas swiftly hitting their stride in the opening session as Sri Lanka slumped from an overnight score of 64-3 to 80-5.

However, Chandimal stalled Pakistan's momentum, receiving able support from Dhananjaya de Silva (32) and Dilruwan Perera (48), as Yasir Shah proved particularly ineffective.

Part-timer Haris Sohail ultimately claimed the key wicket, Chandimal slicing a short and wide delivery to Masood at backward point.

Dilruwan added more valuable runs following Chandimal's exit, before Afridi wrapped up the innings with two wickets in three balls.

If Sri Lanka sensed an opportunity to seize control heading into day three, they were soon left frustrated as Abid and Masood counter-attacked effectively.

Masood survived a scare when a Sri Lanka appeal for lbw was rejected and the on-field decision stood as a review showed the ball would only have clipped leg stump.

He and Abid then made it through to stumps, with Pakistan just 23 behind as the day came to an end.