Pakistan were 299 for eight at the end of the fourth day’s play after a flurry of wickets in the final session left the hosts on top. They are now 188 runs ahead with only two wickets remaining.
Pakistan's Azhar Ali scored his second century in successive matches even as Sri Lanka eyes victory in the third and final Test in Pallekele on Wednesday.
Earlier, Azhar was unbeaten on 97 as Pakistan went to tea on the fourth day at 210-4 in their second innings, just 99 runs ahead with six wickets in hand.
Sri Lanka, who won the first Test in Galle before the second in Colombo was drawn, need only a draw to secure their first series victory in three years since beating New Zealand 2-0 at home in 2009.
Azhar, who made 157 in the Colombo Test, held the innings together with his innings of 136 for over six hours, hitting thirteen boundaries as he reached his fourth Test century.
The right-hander put on 94 for the second wicket with his overnight partner Mohammad Hafeez and 48 for the third with Younis Khan after Pakistan resumed the day at 27-1.
Hafeez, who also hit a century in Colombo, made 52 when he was dismissed just before lunch with Pakistan two runs away from wiping out the first innings deficit of 111 runs.
The wicket of Hafeez, which came against the run of play after Sri Lanka's bowlers failed to contain the flow, allowed Sri Lanka to get hold of the match ahead of the final day’s play.AFP.