Sri Lanka established a 109-run first-innings lead over Pakistan on day three of the third and final Test in Pallekele before the tourists closed on 27 for one in their second innings.
After played was washed out on day two, Sri Lanka replied to Pakistan's 226 all out with 335, recovering well having been reduced to 44 for three late on day one.
Half-centuries from Tharanga Paranavitana (75), Thisara Perera (74) and Thilan Samaraweera (73) mounted the fightback before Junaid Khan returned figures of five for 71.
Sri Lanka, who lead the series 1-0, ended the day in the ascendency when Nuwan Kulasekara trapped Taufeeq Umar in front for four, leaving Pakistan still trailing by 82 runs.
Paranavitana and Samaraweera added 143 together for the fourth wicket to steer Sri Lanka out of troubled waters before both were dismissed by Saeed Ajmal.
Angelo Mathews (10) and Prasanna Jayawardene (20) fell cheaply but Perera forged Sri Lanka ahead, hitting five fours and two sixes in 85 balls, in partnership with Nuwan Kulasekara, who scored 33.
Junaid wrapped up his third five-wicket haul in Tests with the wickets of Mathews and Kulasekara.
It took Sri Lanka just 14 balls to get a wicket when Pakistan batted again, ensuring that they will begin day four in a strong position.
They won the opening Test by 209 runs in Galle and the second match in Colombo was a rain-affected draw.
© Cricket World 2012
Open an account with bet365 today and qualify for up to £200 in free bets with our fantastic 100% Deposit Bonus.