The tourists, who conceded a lead of 177 runs after being dismissed for 138 in the first innings, closed the third day's play at 171 for two in their second knock.
When bad light halted play an hour early, Pakistan trailed by just six runs with eight wickets in hand, promising a keen tussle between bat and ball over the next two days.
Sri Lanka, looking for a series-levelling win after losing the first Test in Galle, removed Mohammad Hafeez cheaply for eight before lunch, caught in the slips by Kumar Sangakkara off Angelo Mathews.
Shehzad was dismissed off the first ball after tea, top-edging a hook off Dhammika Prasad, but Younis Khan joined Azhar to put on 42 for the unbroken third wicket.
More From This Section
Azhar was unbeaten on 64 and Younis, determined to make his 100th match special after falling for six in the first innings, closed the day on a watchful 23.
Sri Lanka, who began at their overnight score of 304-9 after a delayed start due to bad weather, were dismissed for 315 in their first innings in reply to Pakistan's 138.
Yasir had claimed seven wickets in Sri Lanka's second innings in Galle to fashion Pakistan's 10-wicket victory.
Sri Lanka were dealt a scare in the field when Chameera, the debutant seamer, went off the field in the morning session after sending down just nine deliveries.
But he returned after lunch to bowl seven more overs and conceded 28 runs without any success.
Veteran left-arm spinner Rangana Herath was also wicketless in 14 overs, while Prasad returned with one for 46 from 13.3 overs.