The hosts were 176-5 when bad light stopped play on day three with Karunaratne on 27 and Dhananjaya de Silva on 30. Having conceded a lead of 147, Pakistan claimed four wickets in the second session but the 59-run stand between Karunaratne and de Silva put Sri Lanka in a strong position.
Earlier, Ramesh Mendis claimed 5-47, his third five-wicket haul in Tests, as Sri Lanka bowled out Pakistan for 231 to secure a significant lead.
Resuming on 191-7, Yasir Shah and Hasan Ali batted resolutely to deny Sri Lanka any breakthrough in the first hour. Once Prabath Jayasuriya (3-80) removed Hasan, however, Sri Lanka did not take long to polish off the Pakistan tail with Mendis dismissing Nauman Ali and Yasir.
Yasir faced 97 balls for his 26 and was the last man out. Sri Lanka, having decided Karunaratne would bat only if required, sent Niroshan Dickwella into open with Oshada Fernando.