Mathews (77no) grafted his way to a 22nd Test fifty as the hosts reached 228-5 in their second innings, a lead of 291, after dismissing Pakistan for 215 early on Sunday morning.
Upul Tharanga (48), Jehan Mubarak (35) and Dinesh Chandimal (39no) also contributed as Sri Lanka edged closer to??taking the series 2-1, having squared up the contest with a seven-wicket triumph in Colombo last week.
Mathews??? men polished off Pakistan in the second over of the day, Tharindu Kaushal castling Imran Khan (0) to leave Sarfaraz Ahmed (78no) stranded and the tourists with a deficit of 63 runs.
Pakistan made a searing start with the ball, though, reducing Sri Lanka to 35-3, Rahat Ali cleaning up first-innings centurion Dimuth Karunaratne (10) and Lahiru Thirimanne (0) and Ehsan Adil forcing Kaushal Silva (3) to prod to slip.
Rain caused a temporary delay at that point and when the match resumed Tharanga played with real panache, the left-hander adding 45 runs with Mathews before squirting to Rahat at short leg after lunch.
Mathews found further allies in Mubarak and Chandimal, putting on 81 runs with the former and an unbroken stand of 67 with the latter, as the home side seized control before bad light stopped play.