After batting through day four to reach his second Test century, Mathews eventually declared his side's second innings closed at 480 for five late in the morning session.
That left Pakistan with a victory target of 302, which they reduced by 20 runs without loss in five overs before lunch.
Misbah-ul-Haq's side may attempt to chase that on a wicket that has seemingly flattened, although more likely will be content to hold out for a draw after Mathews stole away the initiative they had build over the opening three days.
The 26-year-old all-rounder, who hit 91 as Sri Lanka managed only 204 in their first innings, reached three figures for the first time since taking over the captaincy last February and with Prasanna Jayawardene ensured they batted Pakistan out of the game this morning.
The duo added a further 60 runs in 20.3 overs to extend their unbeaten partnership to 156.
Jayawardene reached his fifth test half-century and finished on 63 when his skipper declared to leave Pakistan with a tricky spell before the break.
Openers Khurram Manzoor and Ahmed Shehzad survived the five overs they were left with without alarm, scoring at four an over to give Pakistan some hope victory is not completely out of the question.
- Sports & Recreation