A late clatter of wickets gave Sri Lanka the initiative heading into the final day of the third Test against Pakistan in Pallekele.
Pakistan slipped from 276 for four to 299 for eight at the close, 188 runs ahead and giving the hosts hope of batting for victory if they can polish off the tail early.
Rangana Herath and Dilhara Fernando did the damage, with Herath taking four for 64 and Fernando three for 65.
Pakistan's problems began when Azhar Ali's outstanding innings came to an end, with the right-hander claiming a second consecutive ton before departing on 136, edging to the wicketkeeper Prasanna Jayawardene off Fernando to leave his side on 276 for five.
Things quickly went into decline for the tourists, with Mohammad Sami following for three, trapped lbw by Fernando, moments later, before Umar Gul went lbw to Herath for a duck and Saeed Ajmal managed just five before also going lbw to Herath.
Asad Shafiq made it to the close unbeaten on 55, with Adnan Akmal yet to score at the other end.
The tourists had begun the day trailing by 84 runs and having lost opener Taufeeq Umar in a short spell before stumps on Tuesday. Mohammad Hafeez and Ali negotiated the swinging ball before they confidently began to erase the deficit.
Hafeez brought up his half-century in 93 balls but moments later, and with Sri Lanka's lead reduced to a single run, he chased a wide Fernando delivery only to edge to Paranavitana at a lone slip to go for 52.
Pakistan lost Younus Khan for 19 after his thin edge to silly point was caught by Tharanga Paranavitana off Herath's delivery.
Pakistan quickly found themselves four down after skipper Misbah-ul-Haq was dismissed for five, becoming Herath's second victim of the session, edging to Mahela Jayawardene at slip.