Mohammad Hafeez was unbeaten on 56 for his ninth half-century, his first in 11 innings, and Ahmed Shezad on 53 as Pakistan still needed another 184 runs to force a win or bat out the remaining 32 overs for a draw - the more likely result.
Pakistan's best winning chase in all Test cricket was 314 against Australia in Karachi in 1994.
Pakistan lost opener Khurram Manzoor early, caught behind off paceman Suranga Lakmal after scoring eight but Hafeez and Shehzad avoided any further loss and put on 94 in an unbroken second wicket stand.
Shehzad, making his Test debut, also hit spinner Rangana Herath for his seventh boundary to reach his maiden fifty in his debut Test.
Earlier, Sri Lanka declared their second innings at 480-5 after batting an hour and 30 minutes but their slow batting showed they had saftey on their minds rather than forcing a lead in the three-Test series.