The hosts gained a first innings lead of 63 runs and then recovered from 35-3 in their second knock to post 228-5 by stumps on a rain-interrupted, but absorbing, third day's play.
Mathews led from the front against a tiring Pakistani attack, adding 45 for the fourth wicket with Upul Tharanga (48) and 81 for the fifth with Jehan Mubarak (35).
Mubarak marked his recall to the Test side after almost eight years with a gutsy 35 before he was caught at short-leg off Yasir Shah in the final session.
Sri Lanka will begin the fourth day with a commanding overall lead of 291 runs with five wickets in hand, having a clear advantage on the wearing pitch to break the 1-1 deadlock in the series.
"We need to bat one more session to push Pakistan out of the game," said Mubarak. "The new ball is due in 10 overs and if we can survive that, we can get a lead of about 380.
- 'Tough from here' -
=====================
Pakistan coach Waqar Younis admitted his team had their backs against the wall, but vowed to fight until the end.
"It's going to be tough from here, but we are going to fight and not let it go easily," the former fast bowler said.
"We will try and slow down the game, fight hard to get some more wickets and then see how it goes. This pitch is still good for batting and we should try and make a game of it.
